【发布时间】:2016-03-15 18:50:02
【问题描述】:
我想在控制器中添加一个类来更改 if 函数通知中出现的消息颜色
这是我的控制器
def send_password
@user=User.find_by_email(params[:user][:email])
if @user.present?
@user.send_reset_password_instructions
flash[:notice] = "Reset password instructions have been sent to #{@user.email}."
redirect_to reset_password_path, notice: "Reset password instructions have been sent to #{@user.email}."
else
return redirect_to reset_password_path, notice: "User is not available."
end
end
end
请帮忙。
我尝试过并以这样的形式给出,但它不起作用。
<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: {method: :post}) do |f| %>
<% if f.error_notification == 'User is not available' %>
<h1 class='reset-error-message'><%= f.error_notification %></h1>
<% else %>
<h1 class='reset-success-message'><%= f.error_notification %></h1>
<% end %>`
然后在控制器中我尝试这样也不起作用
if @user.present?
@user.send_reset_password_instructions
flash[:notice] = "Reset password instructions have been sent to #{@user.email}."
redirect_to reset_password_path, notice: "Reset password instructions have been sent to #{@user.email}.",class:"reset-success-message"
else
return redirect_to reset_password_path, notice: "User is not available., class:"reset-error-message"
end
【问题讨论】:
-
请告诉我们您已经尝试过什么。
标签: ruby-on-rails ruby ruby-on-rails-3 model-view-controller