简体   繁体   中英

Rails devise error “NoMethodError … merge”

I was trying to make a User model with devise (so far in my application I have not had a problem with making Models or adding attributes). I run

rails g devise user

Which creates this:

  invoke  active_record
  create    db/migrate/20140930235224_devise_create_users.rb
  create    app/models/user.rb
  invoke    test_unit
  create      test/models/user_test.rb
  create      test/fixtures/users.yml
  insert    app/models/user.rb
  route  devise_for :users

Then I try to run

rake db:migrate

Which gives me the following

rake aborted!
NoMethodError: undefined method `merge!' for #<ActionDispatch::Routing::Mapper::Scope:0x9fc73a4>
/home/user/Desktop/MyApp/config/routes.rb:2:in `block in <top (required)>'
/home/user/Desktop/MyApp/config/routes.rb:1:in `<top (required)>'
/home/user/Desktop/MyApp/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

What could be the problem?

Line 2 for routes is:

devise_for :users

And line 5 for environment is:

Rails.application.initialize!

Check what devise version you have installed by running:

bundle show devise

With the latest version of Rails 4.2.0, devise will need to be upgraded to 3.4.0 or higher. To do so, specify in your Gemfile:

gem 'devise', '~> 3.4.0'

Then run:

bundle update devise

It looks like this may be a problem with Devise and the latest version of Rails. Have a look at these issues on Devise Github:

This blog post explains that there is a branch with the fix, however, if you are going to be using this in production you should probably wait until Devise merge the fix into master.

Updating the version of devise from 3.3.0 to 3.4.0 in my Gemfile and running bundle update devise worked like magic for me. Im running rails 4.2.0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM