Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After updating to Rails 5 and Devise 4.0.0.rc1, the devise authenticate_user! method is not defined

I had a rails app which was running perfectly with devise 3 and rails 4. I updated rails to 5 and it gave DEPRECATION WARNING: alias_method_chain is deprecated. So i had to change the devise version to 4.0.0.rc1.

Now it seems like the devise is not generating the methods like authenticate_user!, is_admin etc..

I am getting the following error

Before process_action callback :authenticate_user! has not been defined (ArgumentError)

I tried everything including, uninstall devise and install again, then tried to create a separate model from scratch and still the methods are not defined.

Any ideas please ?

like image 895
Hassan Avatar asked Feb 14 '16 16:02

Hassan


3 Answers

The answer for this is to simply change:

skip_before_action :authenticate_user!

to ---

skip_before_action :authenticate_user!, raise: false

https://github.com/plataformatec/devise/issues/4207 https://github.com/thoughtbot/clearance/issues/621

like image 85
hellion Avatar answered Nov 04 '22 08:11

hellion


I could identify the issue, in rails 5, there will be an exception if the skipping method is not defined at the time of calling unless we add :unless condition.

like image 22
Hassan Avatar answered Nov 04 '22 06:11

Hassan


Until rails5 support lands in devise itself, you can try using this fork:

gem 'devise', github: 'twalpole/devise', branch: 'rails5'
like image 1
failpractice Avatar answered Nov 04 '22 07:11

failpractice