remcoh
April 28, 2008, 11: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?
remcoh
April 28, 2008, 11:38am
2
Hi Remco
Is that a typo and there is a spcae between <%= and select_tag in your
code?
remcoh
April 28, 2008, 11: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”
remcoh
April 28, 2008, 11:59am
4
I am aware of that, but i am afraid that doesn’t solve my problem.
Visit Indonesia 2008 wrote:
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”
remcoh
April 28, 2008, 12:41pm
5
Controller:
@locations = Location.find(:all)
@selected = Location.find(2)
View :
<%= select_tag
“location”,“<option value="@selected.id ">
@selected.name ”+
options_from_collection_for_select(@removed_email_address @domain.invalid_a, :id,
:name) %>
what do you think?
Reinhart
http://teapoci.blogspot.com
remcoh
April 28, 2008, 12:43pm
6
CORRECTION
<%= select_tag
“location”,“<option value="#{@selected.id }">
#{@selected.name }”+
options_from_collection_for_select(@removed_email_address @domain.invalid_a, :id,
:name) %>
Reinhart
http://teapoci.blogspot.com
remcoh
April 28, 2008, 3:08pm
7
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)) %>
remcoh
April 28, 2008, 3:34pm
8
Chris B.:
<%= 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)) %>
On Apr 28, 9:34 am, Visit Indonesia 2008 <rails-mailing-l…@andreas -