[Rails] Re: Drop-down menu from a belongs_to association
Leonel *-* wrote:
> I'm trying to enter a client (from clients table (model), client_id)
> into a form for appointments. The client_id is supposed to be entered
> into the appointments table.
>
> If I use
> <div class="field">
> <%= f.label :client_id %><br />
> <%= select ("post", "client_id", Client.all.collect {|client|
> [client.name,client.id]}, :prompt => "Select client" ) %>
> </div>
>
> I get a drop down menu with clients,
...but never, ever do database access in the view! That belongs in the
controller.
> but when I submit it, it tells me
> that it's blank. so I add an "f." to select, like this
>
> <div class="field">
> <%= f.label :client_id %><br />
> <%= f.select ("post", "client_id", Client.all.collect {|client|
> [client.name,client.id]}, :prompt => "Select client" ) %>
> </div>
That is the correct syntax for the f.select call, but may not be
supplying the correct values. What does the generated HTML from that
select look like? Or do you get the error before it even gets to that
point?
This is a case where collection_select will make your life easier.
Best,
--
Marnen Laibow-Koser
http;//www.marnen.org
marnen@marnen.org
--
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@googlegroups.com.
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.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home