in Crafts

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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Related Content by Tag