I have a user who has a list of friends on displayed on his webpage. He can add each friend to a group like, Family or Friends. To implement this , I have the select_tag /form_tag block inside a loop in my view as shown: <% @user.friend.each do |friend| %> <%= form_tag({:controller => ''friendship'', :action => ''addgroup'', :id => friend.screen_name} ) %> <%= select_tag( "groupname", options_for_select(%w{ Family Friends })) %> <%= submit_tag "Add #{friend.name}" %> <% end %> <% end %> On submit the controller friendship/addgroup is invoked with parameter :id => friend.screen_name. I also access params[:groupname] in addgroup. My problem is that even though this is in a loop, when I click on "Add friend" and submit the form the :id => screen_name is always the first friend for the user in the database. What am I doing wrong ? Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Doesn''t submitting a form, submit all the params on the page, regardless of which form they''re in? I''m probably wrong on that though. On Apr 23, 3:15 pm, Maia <meenalp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a user who has a list of friends on displayed on his webpage. > He can add each friend to a group like, Family or Friends. > To implement this , I have the select_tag /form_tag block inside a > loop in my view as shown: > > <% @user.friend.each do |friend| %> > <%= form_tag({:controller => ''friendship'', :action => > ''addgroup'', :id => friend.screen_name} ) %> > <%= select_tag( "groupname", options_for_select(%w{ Family > Friends })) %> > <%= submit_tag "Add #{friend.name}" %> > <% end %> > <% end %> > > On submit the controller friendship/addgroup is invoked with > parameter :id => friend.screen_name. I also access params[:groupname] > in addgroup. > My problem is that even though this is in a loop, when I click on "Add > friend" and submit the form the :id => screen_name is always the > first friend for the user in the database. > What am I doing wrong ? > Thanks--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Try distinguishing the forms by giving them differing names. Eg <%= form_tag({:controller => ''friendship'', :action => ''addgroup'', :id => friend.screen_name}, :name => "addgroup_form_#{friend.id}" ) %> Jan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---