I am going through the Rails API docs for collection_select
and they are god-awful.
The heading is this:
collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})
And this is the only sample code they give:
collection_select(:post, :author_id, Author.all, :id, :name_with_initial, :prompt => true)
Can someone explain, using a simple association (say a User
has_many Plans
, and a Plan
belongs to a User
), what I want to use in the syntax and why?
Edit 1: Also, it would be awesome if you explained how it works inside a form_helper
or a regular form. Imagine you are explaining this to a web developer that understands web development, but is 'relatively new' to Rails. How would you explain it?
Best Answer
Or your example can be represented as the following code:
This isn't documented in the
FormBuilder
, but in theFormOptionsHelper