Hi, I have a really simple problem with ruby on rails. Using a basic
tutorial and scaffolding I have a form with lines like this:
Game 1: <%= Game.find('1').game %>
<%= text_field 'user', 'game_1' %>
and I want to change it from a text field to a drop down menu with
three hardcoded values (“Home”, “Away” and “Draw”).
If someone could help me out that’d be great.
Thanks,
Craig
On 9 Apr 2008, at 13:53, Craig O Connor wrote:
select ‘user’, ‘game_1’, %w(Home Away Draw)
should do the trick.
Fred
On Wed, Apr 09, 2008 at 05:53:56AM -0700, Craig O Connor wrote:
Hi, I have a really simple problem with ruby on rails. Using a basic
tutorial and scaffolding I have a form with lines like this:
Game 1: <%= Game.find('1').game %>
<%= text_field 'user', 'game_1' %>
and I want to change it from a text field to a drop down menu with
three hardcoded values (“Home”, “Away” and “Draw”).
<%= select ‘user’, ‘game_1’, %w(Home Away Draw), :include_blank => true
%>
You may or may not want include_blank
See
http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M000940
If someone could help me out that’d be great.
Thanks,
Craig
–Greg
For Static
<%= select_tag “recipro”, options_for_select([ “Received”, “Sent”,
“Go”],
“Received”) %>
For Dynamic
<%= select(“fir”, “country”, @top.collect {|p|[p.id,
p.countryname]},{:include_blank => ‘Select Country’}) %>