I have a select with values of company names. But I use the id from that table in the select list in the form, not names. I get it with: @userlist = User.find(:all, :order => "company").map { |s| [s.company,s.id]} If I want to get the company name, also in that table, how do I do that? Can I have a hidden field and tell that to get the company name from the selected id of @userlist directly? Or should I have something in the following action where the record is created, picking up the company name? I hope you understand. I have some problem with the logic here :-) In php I would normally have a mysql select in the action after the form to get the selected value. However, I have a feeling that there is a smarter way in RoR. -- 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 -~----------~----~----~----~------~----~------~--~---
Pål Bergström wrote:> I have a select with values of company names. But I use the id from that > table in the select list in the form, not names. I get it with: > > @userlist = User.find(:all, :order => "company").map { |s| > [s.company,s.id]} >I guess I must be able to get it from the created array as "s.company,s.id". Can this be right? The select looks like: <%= select(''group'', ''user_id'', @userlist ) %> So can I should be able to get the value by: @userlist[@group.user_id] And then add that in a hidden field. <%= hidden_field ''group'', ''name'', ''?''%> But not sure how to write it correctly. -- 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 -~----------~----~----~----~------~----~------~--~---