Search code examples
ruby-on-railsform-helpers

f.select Bad arg


I am trying to use the form_for select helper and I am getting an error trying to make a selection of numbers. This is my line:

<%= f.select(:reminder, options_for_select([ ['0','0'], ['10','10'], ['25','25'] ], {}, {:class => 'form-control'} )) %>

and I am getting this error:

wrong number of arguments (3 for 1..2)

I have tried formatting my syntax a lot of different ways but I am at an impasse. Thank you anyone who knows where I am going wrong with my syntax for the select helper. BTW I was useing this page as a reference:

http://guides.rubyonrails.org/form_helpers.html#making-select-boxes-with-ease http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select


Solution

  • Your closing round bracket for options_for_select is at the wrong place. Try:

    <%= f.select(:reminder, options_for_select([ ['0','0'], ['10','10'], ['25','25'] ]), {}, {:class => 'form-control'} ) %>
    

    options_for_select takes 1 or 2 arguments (2nd argument is optional). Because of the misplaced closing bracket, you are passing 3 arguments to it.