我很难用我的FormTagHelper修复这个问题,在这里,我试图传递的params被解释为方法,因此没有方法错误。
以下是您的看法:
<%= form_tag update_user_email_admin_user_path do %>
<%= text_field :user, :email, placeholder: 'E-mail or user id' %>
<%= text_field :user, :new_email, placeholder: 'New e-mail' %>
<%= submit_tag "Update email", class: 'btn-1 btn-round btn-size-2' %>
<% end %>下面是控制器操作(供您参考):
def update_user_email
user_check = User.find_by_email(params[:user][:new_email].downcase.strip)
if user_check.blank?
@user.email = params[:user][:new_email].downcase.strip
@user.save
flash[:notice] = "Email updated"
else
flash[:alert] = "This email is already being used by someone else!"
end
end当我在开发中加载页面时,这是无方法错误:
NoMethodError at /admin/users/195455 undefined method 'new_email' for #<User:0x007f9198c3f560>
这让我感到困惑,因为我在应用程序中使用了其他几个FormTagHelpers,语法几乎相同,而且它们工作得很好。
会喜欢对这件事多加观察的。我是n00b,非常感谢!!
发布于 2013-10-09 05:38:45
因为它假设您试图在User字段中保存new_email值,所以users表中不存在该值。请在这种表格中使用text_field_tag。您可以在这里找到文档:
<%= form_tag update_user_email_admin_user_path do %>
<%= text_field_tag 'email', nil , placeholder: 'E-mail or user id' %>
<%= text_field_tag 'new_email', nil , placeholder: 'New e-mail' %>
<%= submit_tag "Update email", class: 'btn-1 btn-round btn-size-2' %>
<% end %>希望它能help.Thanks
https://stackoverflow.com/questions/19263260
复制相似问题