hi all,
i need help in populating a combo box with table data.
any sample code out there?
ochomo
hi all,
i need help in populating a combo box with table data.
any sample code out there?
ochomo
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
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 O. [email protected]
thanks. i think i luck elaborate ref material.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs