tom@toms-ubuntu:~/rails_projects/routesapp$ rails s
=> Booting WEBrick
=> Rails 3.2.16 application starting in development on http://localhost:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2016-01-12 10:56:27] INFO WEBrick 1.3.1
[2016-01-12 10:56:27] INFO ruby 1.9.3 (2013-11-22) [x86_64-linux]
[2016-01-12 10:56:27] INFO WEBrick::HTTPServer#start: pid=4751 port=3000
NoMethodError in Page#home
Showing /home/tom/rails_projects/routesapp/app/views/layouts/application.html.erb where line #5 raised:
undefined method `[]' for nil:NilClass
Extracted source (around line #5):
2: <html>
3: <head>
4: <title>Routesapp</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
Rails.root:/ home / tom / rails_projects / routesapp
应用程序跟踪|框架跟踪|完整追踪 app / views / layouts / application.html.erb:5:在`_app_views_layouts_application_html_erb ___ 1001173571477850876_70164200470120'
Routesapp::Application.routes.draw do
get 'page/home'
get 'page/about'
get 'page/contact'
任何想法,评论和建议都将不胜感激。这对我来说是新的。谢谢
答案 0 :(得分:2)
由于您是初学者,请让我解释一下。
您的网页 显示;你有错误:
未定义的方法`[]&#39;为零:NilClass
这是标准的Ruby错误 - 它意味着undeclared variable。
由于Ruby是Object Orientated,因此它会分配&#34; nil&#34;值为NilClass
- 意味着您最终会遇到奇怪的错误。
-
通常,通过调试,您可以引用行号,并查看问题所在。
由于您未包含观点,我只能建议您尝试删除以下行作为测试:
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
如果这些工作可以解决问题,那么您必须填充app/assets/javascripts/application.js
或app/assets/stylesheets/application.css
,或使用类似nodeJS
的内容来解决此类错误。< / p>
您还可以更好地使用以下路线:
#config/routes.rb
resources :pages, path: "page", only: [] do
%w(home about contact).each do |page|
get page
end
end
答案 1 :(得分:0)
Buddy在第5行和第6行接受“申请”,并将“申请”字改为“默认”