简体   繁体   中英

Rails devise undefined method `after_sign_in_path_for'

I have controller

class SessionsController < Devise::SessionsController
  respond_to :js
  layout false

  def create
    self.resource = warden.authenticate(auth_options)

    if resource && resource.active_for_authentication?
      sign_in(resource_name, resource)
    end
  end

end

and my template for it

create.js.erb

<% if user_signed_in?%>
  <%= after_sign_in_path_for(resource) %>
<% else %>
 Erorrs here...
  })
<% end %>

I want redirect to specific page after sign in but have got

NoMethodError - undefined method `after_sign_in_path_for' for #<#<Class

what should i do to fix it?

  Rails.application.routes.draw do
      devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks",:confirmations => "confirmations",:passwords => "passwords", :sessions => "sessions" }
  end

I have a similar implementation can you try this

class Devise::SessionsController < DeviseController
  prepend_before_filter :require_no_authentication, :only => [ :new, :create ]

    def create
      self.resource = warden.authenticate(auth_options)

      if resource && resource.active_for_authentication?
        sign_in(resource_name, resource)
      end

      respond_with resource, :location => after_sign_in_path_for(resource)
    end
end

In ApplicationController

private

  def after_sign_in_path_for(resource)
    stored_location_for(resource) || request.referer || root_path
  end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM