Sorry guys - such an obtuse question, but with all the myriad possibilities out there for using select statements in my rails template, I can''t figure out which one is the best. Here''s my problem: I have a very simple form, which only does one thing: you select a name to add to a project, click the submit button, and the form sends two variables (the id of the name to add to the project (:addpersonid) plus the id for the project for the redirect back(:id)) to an update function very similar to the default scaffolding update function. The names are pulled out of a model (Person), but I want to exclude any names that are already on the project from the dropdown. Here''s my pseudocode: <% form_tag :action => ''update'', :id => @id -%> <select name="addpersonid"> <% for p in @people -%> <% unless @team.include?(p) %> <option value="<%= p.id %>"> <%= p.family_name, :action => "update", :id => @id, :addpersonid => p.id %> </option> <% end %> <% end -%> <%= submit_tag ''OK'' %> </select> <% end -%> I don''t even know if this will work, but even if it does there''s got to be a better way to do this. Anybody got any tips? -- 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 -~----------~----~----~----~------~----~------~--~---
On 7/13/07, Sean Colquhoun <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Sorry guys - such an obtuse question, but with all the myriad > possibilities out there for using select statements in my rails > template, I can''t figure out which one is the best. Here''s my problem: I > have a very simple form, which only does one thing: you select a name to > add to a project, click the submit button, and the form sends two > variables (the id of the name to add to the project (:addpersonid) plus > the id for the project for the redirect back(:id)) to an update function > very similar to the default scaffolding update function. > > The names are pulled out of a model (Person), but I want to exclude any > names that are already on the project from the dropdown. Here''s my > pseudocode: > > <% form_tag :action => ''update'', :id => @id -%> > <select name="addpersonid"> > <% for p in @people -%> > <% unless @team.include?(p) %> > <option value="<%= p.id %>"> > <%= p.family_name, :action => "update", :id => @id, :addpersonid => > p.id %> > </option> > <% end %> > <% end -%> > <%= submit_tag ''OK'' %> > </select> > <% end -%> > > I don''t even know if this will work, but even if it does there''s got to > be a better way to do this. Anybody got any tips?Perhaps one way might be <%= select_tag "addpersonid", *options_from_collection_for_select*( (@people - @team), :id, :family_name ) -%> Of course I''m not sure what the :action => ''update'', :id => @id, :addperson_id => p.id is in there for. This should be elsewhere in the form surely. HTH Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Of course I''m not sure what the :action => ''update'', :id => @id, > :addperson_id => p.id is in there for. This should be elsewhere in the > form > surely. > > HTH > DanielYes. That was a hasty cut and paste by me. I ended up taking it out after I posted the message. I will try your solution. It looks like the @people - @team part means that you subtract anybody who is in @team from @people, right? Also not sure what those asterisks are doing. But I will look it up in the API if I can find it. THANKS! -- 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 -~----------~----~----~----~------~----~------~--~---
On 7/13/07, Sean Colquhoun <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > > > Of course I''m not sure what the :action => ''update'', :id => @id, > > :addperson_id => p.id is in there for. This should be elsewhere in the > > form > > surely. > > > > HTH > > Daniel > > Yes. That was a hasty cut and paste by me. > I ended up taking it out after I posted the message. > I will try your solution. It looks like the @people - @team part means > that you subtract anybody who is in @team from @people, right?Yes. The association collections that AR returns are delegated to Array. So normal array operations mostly work. Also not> sure what those asterisks are doing. But I will look it up in the API if > I can find it.Not sure what asterisks you mean. I don''t see any. Cheers Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sorry - maybe they''re only coming up as asterisks in my browser. This is what I see: <%= select_tag "addpersonid", *options_from_collection_for_select*( (@people - @team), :id, :family_name ) -%> In any case, I''ll disregard them. Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
On 7/13/07, Sean Colquhoun <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Sorry - maybe they''re only coming up as asterisks in my browser. This is > what I see: > > <%= select_tag "addpersonid", > *options_from_collection_for_select*( (@people - @team), :id, > :family_name ) > -%> > > In any case, I''ll disregard them. Thanks!Must be the formatting from the copy/paste. Sorry about that. Please do disregard those :) Cheers Daniel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---