相关疑难解决方法(0)

设计登录根路由轨道3

嘿,伙计们.所以我想到了这个酷炫的想法,如果你登录然后你得到某种仪表板,否则你得到一个信息/登录/注册页面..所以我该怎么做..

我主要想在Routes中这样做=不是这样的


def index
  if current_user.present?
    render :action => 'logged_in'
  else
    render :action => 'logged_out'
  end
end
Run Code Online (Sandbox Code Playgroud)

提前致谢!

/ Oluf Nielsen

ruby routes ruby-on-rails devise

35
推荐指数
3
解决办法
1万
查看次数

Rails 4 + Devise:为经过身份验证的用户设置默认根路由

我做了一些研究,发现这个问题已经在不同的地方多次解决了:

我尝试按照上面链接中给出的示例进行操作,并在我的routes.rb文件中提出了以下解决方案:

root to: 'pages#home'

devise_for :users, :path => 'account', controllers: { registrations: "registrations", confirmations: "confirmations" }

authenticated :user do
  root 'calendars#index', as: :authenticated_root
end
Run Code Online (Sandbox Code Playgroud)

这里的目标是将unauthenticated用户引导到home网站的常规页面,而authenticated用户将转到他们的仪表板,在应用程序内,即calendars#index路线,在我的路线中定义如下:

calendars GET    /calendars(.:format)                        calendars#index
Run Code Online (Sandbox Code Playgroud)

但是,当我以用户身份登录并访问 时http://localhost:3000/,我一直登陆home网站的常规页面,而不是应用程序内的用户仪表板。

我究竟做错了什么?

authentication ruby-on-rails rails-routing devise ruby-on-rails-4

2
推荐指数
1
解决办法
1892
查看次数