Gem 关于 devise 的问题

rickyscott · 2014年11月03日 · 最后由 rickyscott 回复于 2014年11月04日 · 1761 次阅读

#devise 关于 model 的问题,和跳转路径的问题 ##关于 model 的问题 1.比如我现在创建一个 model(user).

rails g devise backend/user

然后的话我如果在 controller 中在backend/application_controller.rb添加下面的代码

before_action :authenticate_backend_user!

接下来就跳错了 ##关于跳转路径的问题 2.假设我现在已经能够进行登陆了,但是我现在 controller 中有这个目录

  • backend 它是专门放后台的 controller 的。但是我现在想让 devsie 登陆成功后跳转到后台的首页,而不是root页面

你可以重写 after_sign_in_path_for 比如下面这个样子:

class ApplicationController < ActionController::Base
  def after_sign_in_path_for(resource)
    sign_in_url = url_for(:action => 'new', :controller => 'sessions', :only_path => false, :protocol => 'http')
    if request.referer == sign_in_url
      super
    else
      stored_location_for(resource) || request.referer || root_path
    end
  end
end

@meeasyhappy .第一个问题。能不能提醒我一下,你说的。我回去后试一下你说滴.谢谢

需要 登录 后方可回复, 如果你还没有账号请 注册新账号