NdaJunior
NdaJunior

Reputation: 374

Having troubles getting my rails form to work

I've been trying for hours to get my rails form to work but I can't. The error that it keeps throwing says:

ArgumentError at / wrong number of arguments (3 for 1..2)

and the line of code where it says this error occurs is at the f.input line. Any ideas?

.select-width
 = f.label :country 
 = f.input :country, :select, :as => :fancy_select, collection: ['South Africa', 'Nigeria', 'Zimbabwe', 'Mali', 'Namibia'], hint: 'Lorem ipsum hint'

Upvotes: 2

Views: 51

Answers (2)

Sarwan Kumar
Sarwan Kumar

Reputation: 1311

In simple_form, input requires only two parameters.

  1. for field name
  2. hash of options (This parameter is optional)

So, you can use following code. It will work fine.

.select-width
  = f.label :country
  = f.input :country, as: :fancy_select, collection: ['South Africa', 'Nigeria', 'Zimbabwe', 'Mali', 'Namibia'], hint: 'Lorem ipsum hint'

Upvotes: 1

Emu
Emu

Reputation: 5905

I assume you're using simple_form:

I guess it will work:

= f.input :country, collection: ['South Africa', 'Nigeria', 'Zimbabwe', 'Mali', 'Namibia'], as: :fancy_select

You can check the documentation how they define select tag.

Upvotes: 1

Related Questions