简体   繁体   English

滑轨没有路线匹配[GET]“ /”

[英]Rails No route matches [GET] “/”

My Rails application name is Card. 我的Rails应用程序名称是Card。 I have modified the routes and removed the index.html from public directory. 我已经修改了路由,并从公共目录中删除了index.html。 Still I see The page you were looking for doesn't exist. 我仍然看到The page you were looking for doesn't exist. when I visit my home page. 当我访问主页时。 Rake routes displays the root route correctly. 耙式路由会正确显示根路由。

I am using Passenger with Apache. 我正在将Passenger与Apache配合使用。

root@emaillenin:/var/emaillenin/rails/card# cat config/routes.rb
Card::Application.routes.draw do
root :to => "home#index"
end
root@emaillenin:/var/emaillenin/rails/card# ls public/
404.html  422.html  500.html  favicon.ico  robots.txt
root@emaillenin:/var/emaillenin/rails/card# rake routes
root  / home#index
root@emaillenin:/var/emaillenin/rails/card# ls app/controllers/
application_controller.rb  home_controller.rb
root@emaillenin:/var/emaillenin/rails/card# cat app/controllers/home_controller.rb
class HomeController < ApplicationController
  def index
  end
end
root@emaillenin:/var/emaillenin/rails/card# cat app/views/home/index.html.erb
<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>
<h1>Hello, Rails!</h1>
root@emaillenin:/var/emaillenin/rails/card# bundle exec rake assets:precompile
/usr/local/rvm/rubies/ruby-2.0.0-p195/bin/ruby /usr/local/rvm/gems/ruby-2.0.0-p195@global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
root@emaillenin:/var/emaillenin/rails/card# cat config/environments/production.rb | grep config.assets.compile
  config.assets.compile = true
root@emaillenin:/var/emaillenin/rails/card#

This is what I see in the Apache error log: ActionController::RoutingError (No route matches [GET] "/"): 这是我在Apache错误日志中看到的内容: ActionController::RoutingError (No route matches [GET] "/"):

When I do rails server and access my homepage via 3000 port, I see an error page - http://pastebin.com/1eEU3egt 当我使用rails server并通过3000端口访问我的主页时,我看到一个错误页面-http://pastebin.com/1eEU3egt

Even after executing bundle exec rake assets:precompile I see the same error page. 即使在执行bundle exec rake assets:precompilebundle exec rake assets:precompile看到相同的错误页面。

Even after changing config.assets.compile to true results in the same error. 即使将config.assets.compile更改为true后,也会导致相同的错误。

Any way to crack down this issue? 有什么办法可以解决这个问题?

From another SO question : 从另一个SO问题

By default Rails assumes that you have your files precompiled in the production environment, if you want use live compiling (compile your assets during runtime) in production you must set the config.assets.compile to true . 默认情况下,Rails假定您已在生产环境中对文件进行了预编译,如果要在生产中使用实时编译(在运行时编译资产),则必须将config.assets.compile设置为true

# config/environments/production.rb
...
config.assets.compile = true
...

You can use this option to fallback to Sprockets when you are using precompiled assets but there are any missing precompiled files. 使用预编译资产时,可以使用此选项回退到Sprockets,但是缺少任何预编译文件。

If config.assets.compile option is set to false and there are missing precompiled files you will get an "AssetNoPrecompiledError" indicating the name of the missing file. 如果config.assets.compile选项设置为false,并且缺少预编译的文件,则将显示“ AssetNoPrecompiledError”,指示丢失的文件的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM