Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ERROR] wrong number of arguments (given 1, expected 0) #155

Closed
dcangulo opened this issue Aug 16, 2018 · 4 comments
Closed

[ERROR] wrong number of arguments (given 1, expected 0) #155

dcangulo opened this issue Aug 16, 2018 · 4 comments

Comments

@dcangulo
Copy link

dcangulo commented Aug 16, 2018

I have an issue using this gem.

Steps to reproduce:

  1. Terminal: rails new trialapp
  2. Terminal: cd trialapp
  3. Terminal: rails g model User
  4. In db/migrate/xxxxx_create_users.rb add the following:
...
t.string :username
t.string :country_code
...
  1. Terminal: rake db:migrate
  2. Terminal: rails g controller users
  3. In config/routes.rb add the following:
...
resources :users
root 'users#new'
...
  1. In Gemfile add the following:
...
gem 'country_select'
...
  1. Terminal: bundle install
  2. In app/views/users create a new file new.html.erb
  3. In app/views/users/new.html.erb add the following:
<%= form_for User.new, url: root_url do |f| %>
  <%= f.country_select :country_code %>
<% end %>
  1. Terminal: rails s
  2. Open browser and enter localhost:3000 in the address bar.

Expected Output:

A form with a simple select dropdown containing countries.

Actual Output:

ActionView::Template::Error (wrong number of arguments (given 1, expected 0)):
    1: <%= form_for User.new, url: root_url do |f| %>
    2:   <%= f.country_select :country_code %>
    3: <% end %>

Test Environment:

Laptop: MacBook Pro (Retina, 13-inch, Mid 2014)
OS: macOS High Sierra
OS Version: Version 10.13.4 (17E199)
Ruby Version: ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-darwin17]
Rails Version: Rails 5.2.1
Browser: Google Chrome
Browser Version: Version 68.0.3440.106 (Official Build) (64-bit)

@jtFrancisco
Copy link

jtFrancisco commented Aug 16, 2018

I just installed the gem in a new rails 5.2 app, and got the same error.
I asked this as a question on Stackoverflow

@dcangulo
Copy link
Author

Okay, I managed to make it work.

In Step 13 it will throw an error stated above.

Solution:

Adding these steps solved the problem in my case.

  1. Terminal: bundle update
  2. Restart the rails server

Question:

This isn't supposed to be the proper way to handle this right?

@dcangulo
Copy link
Author

dcangulo commented Aug 16, 2018

UPDATE:

It seems like putting gem 'country_select' in the Gemfile and running bundle install will install versioncountry_select (2.5.2).

This version is the version that throws an error stated above.

Then running the Steps 14 and 15 will solve the problem as this updates the gem to version country_select (3.1.1).

Then to solve the problem. We need to explicitly put gem 'country_select', '3.1.1' to let the bundler know that we need the latest version than the old one.

@scudco
Copy link
Collaborator

scudco commented Aug 17, 2018

This is definitely strange. I did some searching, and it looks like bundler doesn't guarantee it will grab the latest version of a gem if you leave the version unspecified. That was not my understanding or expectation of how bundler works. I think I'll update the README in the short term.

Thanks for looking into this.

scudco added a commit that referenced this issue Aug 17, 2018
It appears that bundler may not always install the latest gem version if you leave the version unspecified. This doesn't address the root cause in #155, but hopefully prevents confusion in the future.

Closes #155
scudco added a commit that referenced this issue Aug 17, 2018
It appears that bundler may not always install the latest gem version if you leave the version unspecified. This doesn't address the root cause in #155, but hopefully prevents confusion in the future.

Closes #155
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants