Enrico Teotti
2006-Jul-04 09:33 UTC
[Rails] select(object, method, choices, options = {}, html_options = {})
Hi,
I''m using:
select(object, method, choices, options = {}, html_options = {})
I''ve read the API where there''s this example:
select("post", "person_id", Person.find_all.collect {|p| [
p.name,
p.id ] }, { :include_blank => true })
should give this code:
<select name="post[person_id]">
<option></option>
<option value="1"
selected="selected">David</option>
<option value="2">Sam</option>
<option value="3">Tobias</option>
</select>
The API says:
"By default, post.person_id is the selected option. Specify :selected
=> value to use a different selection or :selected => nil to leave all
options unselected."
But this is not working to me. Is it for anybody?
First I think post.person_id is @post.person_id. Anyway it doesn''t put
the selected property. Even forcing a :selected => value this way:
<%= select(''night'', ''place_id'' ,
Place.find_all.collect {|p| [ p.name,
p.id ] },{:selected => @night.place_id}) %>
doesn''t work.
Thanks,
Enrico
--
"The only thing necessary for the triumph of evil
is for good men to do nothing"
Edmund Burke
Enrico Teotti
2006-Jul-07 10:23 UTC
[Rails] Re: select(object, method, choices, options = {}, html_options = {})
> <%= select(''night'', ''place_id'' , Place.find_all.collect {|p| [ p.name, > p.id ] },{:selected => @night.place_id}) %>casting the value of place_id :selected => @night.place_id.to_i I get what I want. I''m not sure about the reason of this, maybe cause I''m using two models. -- "The only thing necessary for the triumph of evil is for good men to do nothing" Edmund Burke