Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm using Devise 2.2.7 with Rails 3.2.13. Both of the above methods did not work for me: the <code>valid_vontroller?</code> method in <code>Devise::Strategies::DatabaseAuthenticatable</code> does not exist anymore. The <code>Devise.mappings[:user].controllers[:sessions]</code> trick did not work for me either.</p> <p>After digging through <a href="https://github.com/plataformatec/devise/issues/1230" rel="nofollow">this thread</a> I found <a href="https://github.com/plataformatec/devise/blob/714176994b6d9cb97bcf3e78ad3ee4cc149d7ee2/lib/devise/strategies/authenticatable.rb#L96" rel="nofollow">valid_params_request?</a> which is responsible for ensuring that the request should be sent through the authentication system. There is a helper method, <a href="https://github.com/plataformatec/devise/blob/c67de7e91cc3ea201c7cedc0ed71e1f6c76b2d36/lib/devise/controllers/helpers.rb#L97" rel="nofollow">allows_params_authentication!</a>, which is what enables the <a href="https://github.com/plataformatec/devise/blob/ed86361b9289d1af86b9917c005786e81cf92429/app/controllers/devise/sessions_controller.rb#L3" rel="nofollow">Devise::SessionsController</a> to process authentication requests.</p> <p>You can authenticate a user from any controller by:</p> <pre><code>def signin allow_params_authentication! authenticate_user! end </code></pre> <p>If you want to redirect to a custom page when authentication fails:</p> <pre><code>resource = warden.authenticate!({ :scope =&gt; :user, :recall =&gt; "#{controller_path}#login" }) sign_in(:user, resource) </code></pre> <p>I came across the need for handling authentication outside a subclass of <code>Devise::SessionsController</code> by developing an engine that works alongside of Spree Commerce, which already implements devise authentication.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload