I apologize if this is not a devise bug. My development env was working great with passing tests. But, when I pushed to production on heroku my app crashed with the following error.
Unable to load application: ArgumentError: Before process_action callback :authenticate_user! has not been define.
My routes files includes devise_for :users and I did restart my heroku dynos. I ended up changing config.eager_load = false in production and my app came back to life. I'm still on the hunt for the source and the solution.
Versions for rails and devise?
I'm using rails and devise on heroku and it works well.
Rials 5.0.0 and device 4.2.0
weird, same versions here,
just to confirm, did you ran the steps on Readme ?
for me just ran the steps, send to heroku and it works.
I did, but I am going to double check through the readme.
other quick question, did you ran rails db:migrate on heroku?
I asked because when doesnt run, heroku can throw some weird exceptions like it.
I did migrate. I changed config.eager_load to true in development and I get the exact same error. It doesn't occur on page load, it occurs when the server is trying to start.
/Users/LilWayne/.rvm/gems/ruby-2.3.1@rails_4/gems/activesupport-5.0.0/lib/active_support/callbacks.rb:641:in `block (2 levels) in skip_callback': Before process_action callback :authenticate_user! has not been defined (ArgumentError)
So, the error is occurring when calling "skip_before_action :authenticate_user!". I'm still not sure if this is a Devise bug or an implementation issue.
Ok,
yeah, what you can do is create an other superclass of ApplicationController
that doesnt contains the authenticate_user!.
or just skip it with an unless: :devise_controller? for example.
It's a possible solution, but how I told, it works for me on the same environment.
It seems this is a Rails 5 feature. Rails 5 will throw an error if the method you are trying to skip is not defined. Sorry, for treating Devise issue like StackOverFlow. But, I honestly thought it was a Devise method bug.
skip_before_action :authenticate_user!, unless: :devise_controller? still results in the same error. It also affects the Pundit gem when calling "skip_after_action :verify_authorized".
I'm sure there is a rails solution. I'm gonna close this and move over to StackOverFlow with this.
Thank you @leonardoprg !
In case someone else ends up here thinking this is related to Devise here is the answer: (this error has nothing to do with any gems...it is due to changes in the skip_xxx_action in rails 5)
Simply change ---
skip_before_action :authenticate_user!
to
skip_before_action :authenticate_user!, raise: false
atstockland: nope that doesn't work because the skip_before_action won't work, and that brings back the original problem, too many redirects...
I'm having a similar issue with Rails 5 and Devise 4.2.0.
before_action :authenticate_user! returns:
Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)
Sorry for commenting here - This is the only place I could find any mention of the problem :/
@gwalshington - I tried to move this over to SO, but that proved a pain. People wanted to know the history of the question w/o referring to this issue. It's been a while since I addressed this issue, so I can't quit remember what I did. The answer I proved above is no longer valid and it appears that code has been removed from my app. Here is some relevant code from my application_controller---I hope it helps.
after_action :verify_authorized, except: :index, unless: :devise_controller? # pundit
after_action :verify_policy_scoped, only: :index, unless: :devise_controller? # pundit
before_action :authenticate_user!
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
added_attrs = [:username, :email, :password, :password_confirmation, :remember_me, :current_password]
devise_parameter_sanitizer.permit :sign_up, keys: added_attrs
end
@atstockland thank you!
@atstockland Do you mind linking your SO thread here?
Here's an SO question discussing this: http://stackoverflow.com/questions/35394261/after-updating-to-rails-5-and-devise-4-0-0-rc1-the-devise-authenticate-user-me
Most helpful comment
In case someone else ends up here thinking this is related to Devise here is the answer: (this error has nothing to do with any gems...it is due to changes in the skip_xxx_action in rails 5)
Simply change ---
skip_before_action :authenticate_user!
to
skip_before_action :authenticate_user!, raise: false
https://github.com/thoughtbot/clearance/issues/621