【问题标题】:Use devise to route to specific url使用 devise 路由到特定的 url
【发布时间】:2015-11-12 16:57:45
【问题描述】:

当一个未登录的用户访问我的主页时,他会被重定向到users/sign_in,它有一个登录表单。当用户登录时,他会被重定向到页面的根目录。 http://localhost:3000/#/_=_

但我希望将用户重定向到此网址http://localhost:3000/#/home

我在设计页面上找到了this

def after_sign_in_path_for(resource)
  current_user_path
end

但我不确定我应该如何更改此代码以设计将我的用户重定向到 http://localhost:3000/#/home,这对应于 router-ui 状态。

  .state('home', {
    url: '/home',
    templateUrl: '../assets/angular-app/templates/_home.html.haml',
    controller: 'mainCtrl',
    resolve: {
      postPromise: ['posts', function(posts){
        return posts.getAll();
      }]
    }
  })

【问题讨论】:

    标签: ruby-on-rails redirect devise


    【解决方案1】:

    在你的应用控制器中试试这个

    def after_sign_in_path_for(resource)
       "your_path_here"
    
    end
    

    例如,如果你想去 root_path 那么 "your_path_here" = root_path

    【讨论】:

    • 这将如何将我的用户重定向到#home 部分?
    • @PeterBoomsma 您必须指定登录后要重定向的路径。
    • 你能举个例子吗? def after_sign_in_path_for(resource) root_path#home end 不起作用,因为它把家赶出去了。
    • home 是您的操作名称吗?如果是,那么您的控制器的名称是什么?
    • 我用 router-ui 创建了一个 home 状态动作,它会在 url 为 #home 时做出反应。所以这就是为什么我想通过 url 去#home。
    猜你喜欢
    • 2014-08-19
    • 1970-01-01
    • 2018-02-25
    • 1970-01-01
    • 2013-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多