如果数据==条件,如何用占位符覆盖数据?

How to override data with placeholder if data == condition?

用户可以通过电子邮件和 facebook 注册。如果他通过 Facebook 注册,则会生成一封随机电子邮件,让他完成验证过程。该电子邮件以 @mailinator.com.

结尾

现在,如果用户想要电子邮件提醒他的挑战,那么如果该电子邮件以 mailinator.com 结尾且带有占位符 "Enter Email",我们如何替换默认电子邮件?

挑战控制器

class ChallengesController < ApplicationController
  before_action :update_user_email, if: proc {|c| c.current_user.present? && c.params[:email].present? }

  def update_user_email
    email = params[:email]
    current_user.update_attribute(:email, email)
  end
end

挑战形式

<%= form_for(@challenge)  do |challenge| %> 
   <%= f.collection_check_boxes :send_email, Date::ABBR_DAYNAMES, :downcase, :to_s %>
    Send email to <%= text_field_tag :email, current_user.email %>
<% end %> 

用户模型

def self.from_omniauth(auth)
  user.email = SecureRandom.hex + "@mailinator.com"
  user.save!
end

我想你想要这样的东西。

<% if current_user.email.end_with? "@mailinator.com" %>
  <%= email_field_tag :email,  nil, placeholder: 'Enter email...' %>
<% else %>
    Send email to <%= text_field_tag :email, current_user.email %>
<% end %>