in Programming, Uncategorized

What arguments does collection_select accept?

What arguments does collection_select accept? That what I wondered when I saw this line in the views.

<%= f.collection_select :category_id, Category.order(:name), :id, :name %>

The answer was in the Ruby on Rails API.

collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})

So the first line of code passed in an object, then a method to order the categories. :id is the value that is submitted with the form. :name is what is displayed in the select dropdown.

Write a Comment

Comment