Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!
like image 522
Mike Bean Avatar asked Oct 01 '14 00:10

Mike Bean


3 Answers

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
like image 89
lorindaapps Avatar answered Oct 14 '22 02:10

lorindaapps


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:

  • Issue 3158
  • Issue 3206
  • Issue 3151

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.

like image 24
Tom Kadwill Avatar answered Oct 14 '22 01:10

Tom Kadwill


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.

like image 34
Buhiire Keneth Avatar answered Oct 14 '22 03:10

Buhiire Keneth