most probably you want to use the collection_select helper in your
view
first, in your controller action, grab the contents of the table you
want to use to populate the combo
e.g.
class TestController < ApplicationController
def index
@categories = Category.find(:all)
end
end
Then in your view, add the following code to insert a form and combo
<select> box
<% form_for :articles do |f| %>
<%= f.collection_select(:category_id, @categories, :id, :name) %>
<% end %>
This is assuming you have a table in your db named categories which
has an ''id'' and ''name'' column, and you want
to save the id into the
column ''category_id'' in the table ''articles''
Just substitute out these names if yours are different.
I find this is the best place to read up on the myriad helpers and
methods available in rails: http://www.gotapi.com/rubyrails
On Dec 30, 5:28 pm, Zablon Ochomo
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> hi all,
> i need help in populating a combo box with table data.
> any sample code out there?
>
> ochomo
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---