Ruby on rails 3 如何更新属性';:什么原因';在rails3中使用单选按钮组的模型用户
我想在会话中的页面上更新模型用户的属性“:what_cause”。用户单击3个单选按钮中的一个,相应的值应传输到更新该值的方法。 我编写了以下代码-Ruby on rails 3 如何更新属性';:什么原因';在rails3中使用单选按钮组的模型用户,ruby-on-rails-3,Ruby On Rails 3,我想在会话中的页面上更新模型用户的属性“:what_cause”。用户单击3个单选按钮中的一个,相应的值应传输到更新该值的方法。 我编写了以下代码- <%= form_for :user do |f| %> <label>Pratham</label> <%= f.radio_button :what_cause, "pratham" %> <label>Kali</label> <%=
<%= form_for :user do |f| %>
<label>Pratham</label>
<%= f.radio_button :what_cause, "pratham" %>
<label>Kali</label>
<%= f.radio_button :what_cause, "kali" %>
<label>Akshaya</label>
<%= f.radio_button :what_cause, "akshaya" %>
<%= f.submit "Save", :controller => "users_controller", :action => "change_cause", :method => "put" %>
<% end %>
但它不起作用。请开导我。我是RAILS的新手 这个问题被排序了,我想现在它只显示了-“未定义的方法”[],用于nil:NilClass”,但是:what\u cause在其中有值。这不是零。你能猜出有什么问题吗?
def change_cause
@user.update_attribute(:what_cause, params[:user][:what_cause])
end
def change_cause
@user.update_attribute(:what_cause, params[:user][:what_cause])
end