[英]Ruby on Rails: localhost:3000/my_pages_dont_show_up
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 Rails.root:/ home / tom / rails_projects / routesapp
Application Trace | 应用程序跟踪| Framework Trace | 框架跟踪| Full Trace app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___1001173571477850876_70164200470120' 完整跟踪应用/ 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'
Any ideas, comments, suggestions will be much appreciated. 任何想法,意见和建议将不胜感激。 This is new to me. 这对我来说是新的。 Thanks 谢谢
Since you're a beginner, let me explain. 既然你是初学者,请解释一下。
Your pages are showing; 您的页面正在显示; you've got an error: 你有一个错误:
undefined method `[]' for nil:NilClass 未定义的方法`[]'为nil:NilClass
This is a standard Ruby error - it means undeclared variable . 这是一个标准的Ruby错误 - 它意味着未声明的变量 。
Since Ruby is Object Orientated , it assigns "nil" values to the NilClass
-- meaning that you end up with strange errors. 由于Ruby是面向对象的 ,它为NilClass
赋予“nil”值 - 意味着你最终会遇到奇怪的错误。
-- -
Normally, with debugging, you'll be able to reference the line number, and see what the issue is. 通常,通过调试,您将能够引用行号,并查看问题所在。
Because you've not included your view, I can only suggest that you try removing the following lines as a test : 因为您没有包含您的视图,所以我建议您尝试删除以下行作为测试 :
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
If these work to resolve the issue, you'll have to either populate app/assets/javascripts/application.js
or app/assets/stylesheets/application.css
, or use something like nodeJS
which works to resolve errors like this. 如果这些工作解决了这个问题,你必须填充app/assets/javascripts/application.js
或app/assets/stylesheets/application.css
,或使用类似nodeJS
东西来解决这样的错误。
You'll also be better using the following for your routes: 您还可以更好地使用以下路线:
#config/routes.rb
resources :pages, path: "page", only: [] do
%w(home about contact).each do |page|
get page
end
end
好友将“应用程序”放在第5行和第6行,并将“应用程序”一词改为“默认”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.