ruby on rails 3 - How to update an attribute ':what_cause' of model user using group of radio button in rails3 -
i want update attribute ':what_cause' of model user on page in session. user clicks on 1 of 3 radio buttons , corresponding value should transferred method updates it. wrote following code-
<%= form_for :user |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 %>
and here code updation in change_cause method of users_controller.rb-
def change_cause if params[:radio_button] == "pratham" @user.update_attribute(:what_cause, "pratham") end if params[:radio_button] == "kali" @user.update_attribute(:what_cause, "kali") end if params[:radio_button] == "akshaya" @user.update_attribute(:what_cause, "akshaya") end end
but not working. please enlighten me. newbie in rails!!!
def change_cause @user.update_attribute(:what_cause, params[:user][:what_cause]) end
Comments
Post a Comment