[Ruby] How do I add a selection dropdown to a default scaffold form
Bob Marley
mlee1024 at gmail.com
Thu Jun 14 19:06:43 PDT 2007
Say I have this form _form.rhtml, how do I turn the product ID into a drop
down selection instead of a text field?
I am having difficulty finding documentation on how to use the from.select,
this combined w/my noobness of rails
makes it tough to make work.
Do I need to replace the <!--[form:watch]-->/<!--[eoform:watch]--> with a <%
form_for :watches %> / <% end %> ?
thanks for any help offered.
miene
Here's my controller: watch_controller.rb
def new
@watch = Watch.new
@watch.watchdate = Time.now
@productOptions = {"ProductA"=>25, "ProductB"=>32}
end
the view _form.rhtml
<%= error_messages_for 'watch' %>
<!--[form:watch]-->
<p><label for="watch_status">Status</label><br/>
<%= @watch.status %></p>
....lots of scaffold code
<p><label for="watch_archivenumber">Archivenumber</label><br/>
<%= text_field 'watch', 'archivenumber' %></p>
<p><label for="watch_productid">Productid</label><br/>
<%= @productOptions.each{|x| print x.to_s } %><br/> #test to verify hash
prints (it does)
<%= form.select(:productid, @productOptions) %> #How do I turn this into a
drop down selection??? Instead of a text field
<!--[eoform:watch]-->
database looks like this:
drop table if exists watches;
create table watches(
id int not null auto_increment,
status varchar(100) not null default 'set watch',
watchdate DATETIME not null,
buildURL varchar(255) not null, #Horton Report for Build
URL link
installername varchar(100) not null default 'RhapsodyReal.exe
',
extras varchar(255) null default 'pyrhapsody.exe',
#files to copy to viper.qa in comma sep format
archivename varchar(100) null,
archivenumber varchar(100) null,
productid int not null,
primary key(id)
) engine=InnoDB;
if you read this far, again huge thanks for any help,
miene
More information about the Ruby
mailing list