in Web & Tech

Create a select list from Active Record Object in Rails 3

Build the select form in your view…

<% @categories = Category.find(:all, :order=>"title") %>
<%= collection_select(:service, :category_id, @categories, :id, :title) %>

And access the selected value from the controller (inside the create and update methods):

@service.category_id = params[:service][:category_id]

Of course category_id needs to be made accessible in the services model.

Write a Comment

Comment

  • Related Content by Tag