微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何重定向到root-public / index.html?

如何解决如何重定向到root-public / index.html?

| 我希望重定向到我的应用程序/公用文件夹中的index.html。
def get_current_user
   @current_user = current_user
   if @current_user.nil?  
      redirect_to root_path
   end 
end
我该如何实现? 我尚未在我的route.rb中修改根目录(它仍然被注释)
 # root :to => \"welcome#index\"
我收到一条错误消息,指出root_path未定义。 如何修改routes.rb,以便root_path指向public / index.html?     

解决方法

        您要执行的操作与Rails不兼容。 Rails是MVC,C是控制器,V是视图。 因此,其内部需要两者。 好的,默认情况下会显示but2ѭ,但这仅仅是因为绕过了进程。 因此,您可以创建带有
index
动作的
static
控制器及其相应的视图(只需将当前
public/index.html
文件的内容复制/粘贴到其中)。 然后设置:
root :to => \"static#index\"
并且请删除
public/index.html
文件:)     ,        您可以通过将任何非空字符串传递为
:controller
,并将文件路径作为
:action
来为静态文件分配命名路由:
Application.routes.draw do

  root :controller => \'static\',:action => \'/\' 
  # or
  # root :controller => \'static\',:action => \'/public/index.html\'

end

# elsewhere

redirect_to root_path # redirect to /
假设您有
public/index.html
,这就是您要享用的。     ,        在控制器上
 redirect_to root_path ## (will redirect to root \'/\')
    ,        路由文件:
     root \'main#index\'
控制器:
     class MainController < ApplicationController
       def index
         redirect_to \'/index.html\'
       end
     end
并实时使用rails 4控制器动作,这可以像使用M和C并在V上加捻的单页应用程序一样     ,        routes.rb
...
root to: redirect(\'public/index.html\')
...
这会将所有请求重定向到
\'/\'
\'public/index.html\'
。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。