Beginner: help using <select> drop down list

Hi, first time posting here. I’m in the process of learning ruby and the
rails framework and i’ve come to a road block. I started off by using
the Onlamp tutorial online and got a test database and all of the
generated scaffold pages. I am currently working on a drop down box
using the select tag. I figured out how to get values from a ‘name’
column in my Test table, i’m using mysql for database access.

The problem i’m stuck at now is that I want to be able to select a name
from the list and click a button and have it forward to the ‘show.rhtml’
page for the selected name. I’m trying to reformat the ‘list.rhtml’
page that was created by the scaffold generator, so that there is only
this drop down box, instead of having all the rows in the table show up
with all the columns and data.

If anyone can help me that would be great. i’ve googled all day and
found no examples to help me with this.


Hi, Mike,

please try this (fitting it to your needs):

In your controllers list method load all items (in my example books)
into an instance variable:

@books = Book.find(:all)

In your list-view display these books in a select box with:

<%= start_form_tag :action => ‘show_book’ %>
<%= collection_select(:book, :id, @books, :id, :title) %>
<%= submit_tag ‘Show’ %>
<%= end_form_tag %>

after submitting with the show button you can catch a parameter
params[:book][:id] and use this to find the book that you would like to

def show_book
redirect_to(:action => “show”, :id => params[:book][:id])


Thanks for the help, I follow what you are saying. I’m gonna give it a
try and see how it goes.

Thanks again

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs