[英]How Can I Redirect to My Site's Root In a Controller
I'm writing a bit of code to do the login logic for my website. 我正在写一些代码来为我的网站做登录逻辑。 Basically what I want to do is redirect a user who clicked the logout to the home page.
基本上我想要做的是将点击注销的用户重定向到主页。 Unfortunately, my home page is a splash html page so it doesn't show up in Rails' routing scheme.
不幸的是,我的主页是一个启动html页面,所以它没有出现在Rails的路由方案中。 How can I fix this problem?
我该如何解决这个问题?
I handle this by serving up static pages as resources from Rails just the same everything else. 我通过提供静态页面作为Rails中的资源来处理这个问题。 So http://railsroot/pages/home would display a static home page.
所以http:// railsroot / pages / home会显示静态主页。
I use the High Voltage gem from Thoughtbot to make this simple to achieve. 我使用Thoughtbot的高压宝石来实现这一目标。 You can then just redirect to your page using:
然后,您可以使用以下方法重定向到您的页面:
page_path('home')
Define your root in your routes.rb
as 在
routes.rb
定义root
root :to => "main#index"
which will go to your MainController#index
for example. 例如,它将转到您的
MainController#index
。 Then, to redirect to it 然后,重定向到它
redirect_to root_path
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.