I know this is old news for you but thank you! I’ve been having the
same problem and the solution only occurred to me when I read your post.
I’m new to Rails, so i’ve been assuming that i’ve been passing incorrect
parameters to the select function.
For a reason that’s beyond me, the select helper methods fail if you
invoke them using the form object. Drop the “f.” prefix. The select
box is associated with the form via it’s first parameter. You should
pass the same instance variable used in your “form_for” declaration.
This will work:
<% form_for(@user) do |f| %>
__
____<%= f.label “Admin” %>
____<%= select :user, :admin, [ [“True”,1], [“False”,0]] %>
__
__
____<%= f.submit “Create” %>
__
<% end %>
This creates a select box that sets the ‘user’ objects ‘admin’ attribute
to 1 or 0. The first parameter must match the ‘form_for’ instance
variable or they will not be associated with any lines like this;
@user = User.new(params[:user])
I hope that’s clear for anyone having the same nightmare. I found this
page especially useful on select boxes;
http://shiningthrough.co.uk/blog/show/6
Stuart Fellowes wrote: (back in 2006 lol)
I’m getting this error due to a change necessary for my form.
Initially - I was using formhelper where the form_for looked like this:
<%= form_tag :action => ‘create_position’ %>
Now I’ve switched to the scaffold_resource in edge rails where the
forms are setup as such:
<% form_for(:position, :url => positions_path) do |f| %>
So I know that this form_for will also accept the regular formhelpers.
However Im running into a problem with a field, where if i don’t add
the f (i.e. f.select) the page loads fine but the input is never put
into the database.
If I put the f on it generates the undefined method merge error.
Here is the field:
<%= f.select ‘pay’, ‘id’, Pay.find(:all).collect {|p| [p.name, p.id]}%>
Hoping someone can help.
TIA
Stuart