Check out the ActiveRecord::Base#update method where you can pass an array of IDs along with attributes to update all the user records at once.
James On Sep 22, 2009, at 10:12 PM, liquid_rails <cheri.anacle...@gmail.com> wrote: > > It works :) Awesome! > Now I'm trying to figure out the best way to extract the data in the > controller so that I can update the user.approval value for each > user. This is what's being passed: > > Parameters: {"commit"=>"Submit", "user"=>{"6"=>{"approval"=>"1"}, > "1"=>{"approval"=>"1"}, "2"=>{"approval"=>"2"}, "3"=> > {"approval"=>"2"}, "4"=>{"approval"=>"2"}, "5"=>{"approval"=>"2"}}, > "authenticity_token"=>"39757ec52a8cb0e04a7533686976d49388378c02", > "_method"=>"put", "action"=>"approve", "controller"=>"admin/users"} > > Any hints would be appreciated! > Thanks in advance, > > ~Cheri > > > On Sep 22, 12:41 pm, liquid_rails <cheri.anacle...@gmail.com> wrote: >> Great, thanks Jason! I'll try it. - Cheri >> >> On Sep 22, 12:04 pm, Jason King <smathy.w...@gmail.com> wrote: >> >>> No :) >> >>> So, yeah, if you want just a single submit button then you'll want a >>> single form and you should use fields_for with the :index option... >> >>> <% form_for ....etc. do %> <%# ....you can just have a >>> form_tag here if you want %> >>> <% @users.each do |user| %> <%# total aside: this is more >>> Ruby- >>> ish syntax %> >>> <%= other things %> >>> <% fields_for user, :index => user.id do |f| %> >>> <%= f.radio_button :approval ..etc. %> >>> <% end %> >>> <% end %> >>> <%= submit_tag %> >>> <% end %> >> >>> You'll find that all the radio buttons will be indexed, so you'll >>> receive params[:user][id_of_user][:approval] in your controller, so >>> you can easily set the right values for the right user all in one >>> action. >> >>> On Sep 22, 2009, at 11:48 AM, liquid_rails wrote: >> >>>> Thanks, Jason. >> >>>> So, if I have a separate form for each user, is there any way to >>>> have >>>> just one submit button to submit all forms at the same time? >> >>>> Cheri >> >>>> On Sep 22, 11:42 am, Jason King <smathy.w...@gmail.com> wrote: >>>>> The problem is that you've got form_for [:admin, :user] instead of >>>>> form_for [:admin, @user] and then you're expecting (somehow) >>>>> f.radio_button to know which user to use to retrieve the seed >>>>> value. >>>>> Rails is using the last element of that array and calling >>>>> the .approval method on it (hence the error about the user:Symbol >>>>> (ie. :user ) not having that method defined. >> >>>>> You're more likely to want to put the form within the @users >>>>> iteration >>>>> block, so that you have a separate form for each user. You can >>>>> then do: >> >>>>> <% for user in @users %> >>>>> <% form_for [:admin, user] ...etc. do %> >>>>> <%= f.radio_button :approval ...etc. %> >> >>>>> If not, if you want it all in one form, then you won't be able >>>>> to use >>>>> the form_for block helpers, rather you'll need to use >>>>> radio_button_tag >>>>> and setup the values and names manually. >> >>>>> Regards, >>>>> Jason >> >>>>> On Sep 22, 2009, at 11:30 AM, liquid_rails wrote: >> >>>>>> I'm trying to generate a list of users with two radio buttons >>>>>> next >>>>>> to >>>>>> each user where I can either approve or reject a user, all in the >>>>>> same >>>>>> form. >>>>>> The following code, illustrates what I am trying to do and the >>>>>> error I >>>>>> am getting. >>>>>> Does anybody know how to do this? Thanks in advance! - Cheri >> >>>>>> create_table "users", :force => true do |t| >>>>>> t.string "name" >>>>>> t.integer "approval", :default => 0 # 0=needs approval, >>>>>> 1=approved, 2=not approved >>>>>> end >>>>>> ------------------- >> >>>>>> <% form_for [:admin, :user], :url => {:action => >>>>>> "user_approval" } do >>>>>> |f| %> >>>>>> <% for user in @users %> >>>>>> <tr> >>>>>> <td><%= user.id %></td> >>>>>> <td><%= user.name %></td> >>>>>> <td><%= user.approval %></td> #current state of the user's >>>>>> approval status >>>>>> <td><%= f.radio_button :approval,'1' %>"Approve" </td> >>>>>> <td><%= f.radio_button :approval,'2' %>"Reject" </td> >>>>>> </tr> >>>>>> <% end %> >>>>>> <p> <%= f.submit "Submit" %> </p> >>>>>> <% end %> >> >>>>>> --------- >>>>>> Error: >>>>>> undefined method `approval' for :user:Symbol > > --~--~---------~--~----~------------~-------~--~----~ SD Ruby mailing list sdruby@googlegroups.com http://groups.google.com/group/sdruby -~----------~----~----~----~------~----~------~--~---