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 <[email protected]> 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
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---

Reply via email to