0

I have a website and a Rails app.

When a user goes to the website, I want to check if they are logged in or not. If they are, I want to send them to the Rails application. If they are not logged in I want to send them to the website.

pivotaltracker.com has this type of behavior.

What's the best way to go about this? I figure the Rails app needs to do the log in check so it seems the user should always be sent there first and redirect to the website if not logged in?

But it seems like more often than not the result will be to display the website, so it seems like this adds an extra step, and slows things down for the majority of users. But I'm not sure how else to do it.

Any ideas?

4

2 回答 2

0

如果您使用的是设计,您可以:

Dashboard::Application.routes.draw do

  devise_for :users    
  authenticated :user do
    resources :stuffs
    root to: "home#dashboard"
  end

  root to: "home#website"
end

如果登录,这将向用户显示仪表板,如果未登录,则显示“网站”。然后,您可以显示该网站,或重定向到该网站。

于 2012-06-10T18:00:30.510 回答
0

在网站的 web 服务器层检查应用会话 cookie,如果有则将其发送到应用程序,如果没有则继续访问网站。

当然,该应用程序将执行实际检查以查找登录用户并重定向到网站,如果任何闻起来很有趣。

是的,它更复杂。

或者,在测量之前停止尝试优化事物。“似乎”意味着您没有检查数字以了解更频繁发生的情况。(这比预期的更讽刺。我想提醒你“过早的优化”,而不是试图对你大喊大叫。)

于 2012-06-10T17:49:36.980 回答