加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何重定向到root – public / index.html?

发布时间:2020-12-16 20:10:52 所属栏目:百科 来源:网络整理
导读:我希望在我的应用程序/公用文件夹中重定向到index.html. def get_current_user @current_user = current_user if @current_user.nil? redirect_to root_path end end 我该如何实现? 我没有修改root.rb中的根(它仍然被评论) # root :to = "welcome#index" 我
我希望在我的应用程序/公用文件夹中重定向到index.html.
def get_current_user
   @current_user = current_user
   if @current_user.nil?  
      redirect_to root_path
   end 
end

我该如何实现?

我没有修改root.rb中的根(它仍然被评论)

# root :to => "welcome#index"

我得到一个错误,说root_path是未定义的.

如何修改routes.rb,以便root_path指向public / index.html?

解决方法

你想做的不是Rails兼容的.

Rails是MVC,C为控制器,V为视图.

所以它的内部需要两者.

好的,默认情况下会显示public / index.html,但这只是因为过程被绕过.

因此,您可以创建一个具有索引操作的静态控制器,并且它是相应的视图(只需复制/粘贴当前public / index.html文件的内容).

然后设置:

root :to => "static#index"

请删除public / index.html文件:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读