11175
(-- --)
April 28, 2008, 9:33am
1
Many posts I found about this, and many possible solutions, but i just
can't get this simple thing to work: i tried every single solution i
found:
<%=select_tag
"location",options_from_collection_for_select(Location.find(:all), :id,
:name, "2")%>
<%=select_tag
"location",options_from_collection_for_select(Location.find(:all), :id,
:name, 2)%>
<%=select_tag
"location",options_from_collection_for_select(Location.find(:all), :id,
:name, {:selected=>"2"})%>
<%=select_tag
"location",options_from_collection_for_select(Location.find(:all), :id,
:name, {:selected=>2})%>
<%=select_tag
"location",options_from_collection_for_select(Location.find(:all), :id,
:name, {:selected_value=>"2"})%>
is there anybody out there who knows how to do this?
Hi Remco
Is that a typo and there is a spcae between <%= and select_tag in your
code?
Remco Hh wrote:
11175
(-- --)
April 28, 2008, 9:56am
3
I add an additional advice. Remco you should remember that RoR is
designed with MVC. I disagree if you put Location.find(:all) in your
view. Put it in your controller as instance variable, then put your
instance variable into your view.
Controller:
@locations = Location.find(:all)
View :
<%= select_tag
"location",options_from_collection_for_select(@locations , :id,
:name, "2") %>
Feel the taste of ROR by Optimizing MVC. Good luck.
Reinhart
http://teapoci.blogspot.com
"Misguided in programming and paradigm?"
"Ruby and Rails is your appropriate map"
11175
(-- --)
April 28, 2008, 9:59am
4
I am aware of that, but i am afraid that doesn't solve my problem.
Visit Indonesia 2008 wrote:
11175
(-- --)
April 28, 2008, 10:43am
5
CORRECTION
<%= select_tag
"location","<option value=\"#{@selected.id }\">
#{@selected.name }</option>"+
options_from_collection_for_select(@locations -@selected.to_a , :id,
:name) %>
I think you will need to put the select_tag in parentheses like this.
<%= select_tag( "location",
options_from_collection_for_select(Location.find(:all), 2)) %>
11175
(-- --)
April 28, 2008, 1:34pm
7
Chris Barnes:
<%= select_tag( "location",
options_from_collection_for_select(Location.find(:all), 2)) %>
have you tried to run it? you will get error
Reinhart
http://teapoci.blogspot.com
Sorry no I didn't run it but the source of the error is easily fixed.
Lookup options_from_collection_for_select in the docs.
<%=
select_tag( "location",options_from_collection_for_select(Location.find(:all),
"id", "name", 3)) %>