hello, I am a Ruby Rails newbie. I am confused as to how to update in a clean way my User table through an admin html view by passing the update parameters for the record. Ex. I have a User table with the following entries id integer email string internal boolean admin boolean I wan to create a view (html) to see all the users an Update their internal and admin status (boolean) via radio buttons. I want to be able to pass the values for each user correctly to the controller Update action. so I have something like this (pseudo code) <% form_tag :url => { :action => ''update''} do %> <% @internal_users.each do |user| %> <%=h user.email%> <%= radio_button_tag ''user[user.id][internal]'' , true, user.internal %> <%= radio_button_tag ''user[user.id][internal]'', tru, user.admin %> <% end %> <%= submit_tag ''Update'' %> <% end % in the controller I defined an Update Action def update User.update(params[:user].keys, params[:user].values] end Of course this is not working otherwise I wouldn''t asking for help. Can anyone tell me what is the best way to achieve my goal of updating the User internal and admin boolean entries via a html form. Thanks
On Nov 17, 3:39 pm, codefusurfer <nrivera....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > def update > User.update(params[:user].keys, params[:user].values] > endThis would work if params[:user] was of the form {1 => {''internal'' => true}, 2 => {''internal'' => false}} However that''s not what you''ve got. There are several problems: - what you get out of the params hash is always a string ie you''ll be receiving the string ''true'' rather than the boolean value true. If your values are ''1'' and ''0'' then Active Record (if my memory is correct) will do the appropriate coercing to true / false - you''re using radio buttons in a really odd way - seems to that check boxes would be more appropriate - unchecked checkboxes etc don''t submit a value at all, you probably want to either reuse the rails check_box (not the same as check_box_tag) helper or use the same trick as it does (include a hidden field with the same name and the appropriate parameter value). Lastly there are few things as uninformative as saying ''it doesn''t work'' - tell us what goes wrong. Fred> > Of course this is not working otherwise I wouldn''t asking for help. > Can anyone tell me what is the best way to achieve my goal of updating > the User internal and admin boolean entries via a html form. Thanks