Forum: Ruby on Rails drop down menu - getting @params[:id] value.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
James W. (Guest)
on 2006-04-06 20:05
I am looking to get my option drop down list to populate from a model.
In my controller i'm using:

@roles = Role.find(:all, :order => "name")

in my view I have:
<%= collection_select(:id, :name, @roles, :id, :name) %> role <%=
submit_tag("Go") %>

I cannot get just the id of the selected option. If i inspect the params
I get:

{"commit"=>"Go", "action"=>"view_role_rights", "id"=>{"name"=>"1"},

What is going on there? can anyone help?
Wiebe C. (Guest)
on 2006-04-06 20:32
(Received via mailing list)
James W. wrote:

> I get:
> {"commit"=>"Go", "action"=>"view_role_rights", "id"=>{"name"=>"1"},
> "controller"=>"accounts"}
> What is going on there? can anyone help?

I'm somewhat confused why you are supplying :id and :name as first two
arguments. They should be the ActiveRecord::Base object and the method,
instantace, "post" and "author_id". I'm guessing your roles are for
so you'd need something like "user" and "role_id".
This topic is locked and can not be replied to.