简体   繁体   English

Ruby on Rails:localhost:3000 / my_pages_dont_show_up

[英]Ruby on Rails: localhost:3000/my_pages_dont_show_up

When I 'rails server' the localhost:3000 works in my browser (chrome). 当我'运行服务器'时,localhost:3000在我的浏览器中运行(chrome)。 Here's the term: 这是一个术语:

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

But for localhost:3000/page/home the browser displays: 但对于localhost:3000 / page / home,浏览器显示:

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'

I generated the html files shown in the routes.rb file below; 我生成了下面的routes.rb文件中显示的html文件; the html files are located in app/views/page html文件位于app / views / page中

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.jsapp/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.

相关问题 Ruby on Rails Devise Always localhost:3000将被重定向 - Ruby on Rails Devise Always localhost: 3000 will be redirected Ruby on Rails-ActiveRecord :: ConnectionNot在localhost:3000上建立 - Ruby on Rails- ActiveRecord::ConnectionNotEstablished on localhost:3000 Ruby on Rails:http:// localhost:3000无法正常工作 - Ruby on Rails: http://localhost:3000 not working localhost:3000 / my-scope / pages / new throws没有路由匹配{:action =&gt;“show”,:controller =&gt;“pages”} - localhost:3000/my-scope/pages/new throws No route matches {:action=>“show”, :controller=>“pages”} 无法访问localhost:3000 ruby​​ on rails ubuntu - Can not acces localhost:3000 ruby on rails ubuntu Ubuntu,Ruby,Ruby on Rails安装问题(无法访问localhost:3000) - Ubuntu, Ruby, Ruby on Rails Installation Problems (Cant visit localhost:3000) Ruby on Rails在Windows上无法连接到localhost:3000、127.0.0.1:3000和0.0.0.0:3000 - Ruby on Rails can't connect to localhost:3000, 127.0.0.1:3000 and 0.0.0.0:3000 on Windows Ruby on Rails无法访问MAC上的http:/ localhost:3000 - Ruby on rails cannot access http:/localhost:3000 on MAC 在vagrant中无法连接localhost:3000 ruby​​ on rails - can't connect localhost:3000 ruby on rails in vagrant ruby on rails不会加载欢迎页面(localhost:3000) - ruby on rails won't load welcome page(localhost:3000)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM