After I install devise and create a user model. I rake db:migrate
and then I rake routes
. I then get a error with "undefined method `devise_for' for #". What could be causing this error?
-
1Have you added devise to your Gemfile? Can you check if `devise` is present in your Gemfile.lock too? – Dogbert Jan 26 '11 at 22:49
-
my gem file says gem 'devise', :git => 'git://github.com/plataformatec/devise.git' – Yeddie Jan 26 '11 at 23:00
-
Based on the steps you mentioned, you will get this error if you don't have a `devise.rb` under `config/initializers` – Americo Savinon Mar 23 '23 at 09:03
4 Answers
Remember to restart your rails server after installing and configuring devise.

- 2,809
- 1
- 13
- 2
-
2
-
-
I wish the Rails server could watch files and auto-reload. Wasteful, yes, but it'd be damn convenient during development! – ankush981 Apr 22 '20 at 21:31
If you have the Devise gem specified in the Gemfile, just make sure you have the following in your routes.rb file:
devise_for :users
Also, here's a trick to make sure Devise is mapped properly, run: rails c, (the Rails app console) in your app's folder and then the following command line:
Devise.mappings.keys
You should see:
=> [:user]
Cheers!

- 528
- 5
- 14
-
Hi Florin, thanks for your answer. I have "devise_for :users" line on my routes file, however when I run Devise.mappings.keys I got an error. How should I fix this? – CanCeylan Jan 03 '15 at 14:50
-
Hi there - care to specify the error, unless you already found the solution?! – Florin Jan 04 '15 at 16:21
Honestly, I would recommend following these two Railscasts (Episode 209 and Episode 210). The first is a simple and very easy walkthrough for installing Devise and the second is about customizing it to fit your application.
I've watched both episodes and they drastically helped me with Devise, particularly with the customization.
Your best bet is to start from scratch - you'll learn a heck of a lot and have Devise fully installed and functional.
Hope this helps! Good luck.

- 11,836
- 13
- 49
- 66