Noam B.
Noam B.

Reputation: 3250

why do I get syntax error when using f.select?

This is my code:

<%= f.select :question, :part_number, :options_for_select => ([1..5]), options = { :include_blank => true } %>

I keep getting this error:

syntax error, unexpected ')', expecting tASSOC ...= { :include_blank => true } ).to_s); @output_buffer.concat ...

Upvotes: 0

Views: 85

Answers (2)

Bart Jedrocha
Bart Jedrocha

Reputation: 11570

Sometimes the Rails docs can be a bit confusing, but if you're using the select form helper within a form_for @question block, you don't specify the object. Thus, your code would need to change to

<%= form_for @question do |f| %>
  ...
  <%= f.select :part_number, options_for_select((1..5)), include_blank: true %>
  ...
<% end %>

Upvotes: 2

Noam B.
Noam B.

Reputation: 3250

Well, since that I use select and not collection_select, there is no need to specify the object (:question).

So for anyone who comes to this problem, here is the solution:

<%= f.select :part_number, (1..5), { :include_blank => true } %>

Upvotes: 1

Related Questions