Select_tag values from model?

Hello,

I have a form [using start_form_tag] with a select_tag. I need to
populate the values [id and name] from a model. So far all the
examples for populating values of select box from database uses
form_for and form.collection_select method.

Is there a similar way to do that for from_tag and select_tag?

I am happy atleast if I get a method to pass a name and id to the
select_tag, so that the display is name and id is posted.

regards,

raj

See following for detailed doc:

Here is an example:

<%= select(“object”,“selection”,[option1, option2,…], {}, {:class =>
“class”}) %>

Should give you a drop-down with the current value of
@object.selection selected.

Help that helps

Thanks a lot for your reply, Kim.

On 12/1/06, Kim [email protected] wrote:

<%= select(“object”,“selection”,[option1, option2,…], {}, {:class =>
“class”}) %>

I want the dropdown for a model less form. So I do not have an
“object”. I did solve this by a an ugly way.

my form is:

<%= form_tag :action => :agent_call_list%>
<%= @agent = Agent.find (:all, :order => “name”)
collection_select(“blah”, :agent_id, @agent, :id, :name) -%>
<%= submit_tag -%>
<%= end_form_tag %>

in my controller, I give:

params[‘agent_id’] = params[‘blah’][‘agent_id’] if
params.has_key?(“blah”)

params[‘agent_id’] is used by other forms and that’s the place I
expect the value to be. So I check if params[‘blah’][‘agent_id’] is
defined and if so, I copy it’s value to params[‘agent_id’]

Ugly, but works. Though I would have preferred the value from the form
in params[‘agent_id’]

Now if only I can select a particular value in my drop down list.

raj