0

I am using .select to assign a "line_id" to an "instance". The class "Instance" belongs_to "Line".

<%= line_builder.select('instance', 'line.line_id', Line.all.collect {|p| [p.title, p.id ]}, { :include_blank => 'select line' }) %>

this line returns this error:

undefined method `merge' for #<Array:0x007fc3c389e868>

Not quite sure whats going wrong here, but i'm assuming it's the syntax of the .select method because i've never used it before.

What else can I show you to help me figure this out?

1 Answer 1

1

Try with options_for_select:

<%= line_builder.select(:line_id, Line.all.collect {|p| [p.title, p.id ]}, { :include_blank => 'select line' }) %>

Reason it was not working:

You had an extra argument in your select: A select in a Form builder takes as arguments the method to call for update (here line_id, so Rails will call line_id of the object and assign it the value of the select box), second argument is the options for the select, third option is the html_options as a Hash. As you had an extra argument, Rails was expecting your options to be the html_options hash, which was your options of the select.

Sign up to request clarification or add additional context in comments.

5 Comments

undefined method `merge' for #<ActiveSupport::SafeBuffer:0x007fc3c3c02630>on second line.
that second one seems to have done it... any chance you can explain to me why?
You had an extra argument in your select: A select in a Form builder takes as arguments the method to call for update (here line_id, so Rails will call line_id of the object and assign it the value of the select box), second argument is the options for the select, third option is the html_options as a Hash. As you had an extra argument, Rails was expecting your options to be the html_options hash, which was your options of the select. (hope It makes sense ...)
yes, that makes perfect sense, I feel a little misled by apidock.com which shows an additional "object" argument "select(object, method, choices, options = {}, html_options = {}) public"
Yes its confusing but here you are using a form_builder, which already knows the 'object' for the form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.