[英]Rails 4 newbe : Routing Error -
I am very new to rails. 我对Rails很陌生。 No idea how to fix it.
不知道如何解决它。 I cannot even start a simple rails app!
我什至无法启动一个简单的Rails应用程序!
Environment:
Windows 7
Ruby 2.1.0
Rails 4.2.3
First: I ran generate command 第一:我运行了generate命令
D:\\railprojects\\blog>rails generate controller Pages index D:\\ railprojects \\ blog> rails生成控制器页面索引
routes.rb 的routes.rb
Rails.application.routes.draw do
get 'pages/index'
end
pages_controller.rb pages_controller.rb
class PagesController < ApplicationController
def index
end
end
index.html.erb index.html.erb
<h1>Pages#index</h1>
<p>Find me in app/views/pages/index.html.erb</p>
I am getting following error. 我收到以下错误。
http://127.0.0.1:3000/pages http://127.0.0.1:3000/pages
Routing Error
No route matches [GET] "/pages"
Rails.root: D:/railprojects/blog
Application Trace | Framework Trace | Full Trace
Routes
Routes match in priority from top to bottom
Helper HTTP Verb Path Controller#Action
Path / Url
pages_index_path GET /pages/index(.:format) pages#index
Request
Parameters:
None
Screenshot http://i.stack.imgur.com/06W5e.jpg 截图 http://i.stack.imgur.com/06W5e.jpg
Please help. 请帮忙。 If you need more info, please let me know.
如果您需要更多信息,请告诉我。
localhost:3000/pages/index 本地主机:3000 /页/指数
changed to - get 'pages#index' 更改为-获取“ pages#index”
Routing Error
No route matches [GET] "/pages"
Rails.root: D:/railprojects/blog
Application Trace | Framework Trace | Full Trace
Routes
Routes match in priority from top to bottom
You don't have any routes defined!
Please add some routes in config/routes.rb.
For more information about routes, please see the Rails guide Rails Routing from the Outside In.
Helper HTTP Verb Path Controller#Action
Path / Url
Change it to - resources :pages 更改为-resources:pages
ExecJS::ProgramError in Pages#index
Showing D:/railprojects/blog/app/views/layouts/application.html.erb where line #6 raised:
TypeError: Object doesn't support this property or method
Rails.root: D:/railprojects/blog
Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__2066577970_70340560'
Request
Parameters:
None
Toggle session dump
Toggle env dump
GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
HTTP_ACCEPT_ENCODING: "gzip, deflate, sdch"
HTTP_ACCEPT_LANGUAGE: "en-US,en;q=0.8,bn;q=0.6"
REMOTE_ADDR: "127.0.0.1"
REMOTE_HOST: "127.0.0.1"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"
Rails.application.routes.draw do
get 'pages', to: 'pages#index'
end
ExecJS::ProgramError in Pages#index
Showing D:/railprojects/blog/app/views/layouts/application.html.erb where line #6 raised:
TypeError: Object doesn't support this property or method
Rails.root: D:/railprojects/blog
Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__2066577970_70340560'
Request
Parameters:
None
Toggle session dump
Toggle env dump
GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
HTTP_ACCEPT_ENCODING: "gzip, deflate, sdch"
HTTP_ACCEPT_LANGUAGE: "en-US,en;q=0.8,bn;q=0.6"
REMOTE_ADDR: "127.0.0.1"
REMOTE_HOST: "127.0.0.1"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"
Response
Headers:
None
changed to 变成
Rails.application.routes.draw do
get 'pages', to: 'pages#index'
end
/ /
ExecJS::ProgramError in Pages#index
Showing D:/railprojects/blog/app/views/layouts/application.html.erb where line #6 raised:
TypeError: Object doesn't support this property or method
Rails.root: D:/railprojects/blog
Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__2066577970_70340560'
Request
Parameters:
None
Toggle session dump
Toggle env dump
GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
HTTP_ACCEPT_ENCODING: "gzip, deflate, sdch"
HTTP_ACCEPT_LANGUAGE: "en-US,en;q=0.8,bn;q=0.6"
REMOTE_ADDR: "127.0.0.1"
REMOTE_HOST: "127.0.0.1"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"
Response
Headers:
None
try 尝试
localhost:3000/pages/index
or if you want to go on index page with this localhost:3000/pages change routes 或者如果您想使用此本地主机进入索引页面:3000 / pages更改路由
resources :pages
You should point 你应该指出
http://localhost:3000/pages/index
in your browser to reach proper action. 在您的浏览器中采取适当的措施。
This is because of your route configuration: 这是因为您的路由配置:
get 'pages/index'
If you would like to be able to point /pages
, you have to reconfigure it to look like: 如果您希望能够指向
/pages
,则必须将其重新配置为如下所示:
get 'pages', to: 'pages#index'
You can find more about Rails routing here ; 您可以在这里找到有关Rails路由的更多信息;
Good luck! 祝好运!
UPDATE UPDATE
The whole content of config/routes.rb
should look like: config/routes.rb
的整个内容应如下所示:
Rails.application.routes.draw do
get 'pages', to: 'pages#index'
end
First of all, dont use Windows to developing in Rails... YOu will have a lot of headaches. 首先,不要使用Windows在Rails中进行开发……您会头疼不已。 Believe in me.
相信我。
If you dont want to install Linux (like ubuntu), you can use vagrant ( https://www.vagrantup.com/ ). 如果您不想安装Linux(如ubuntu),则可以使用vagrant( https://www.vagrantup.com/ )。
About your error, you defined pages/index
route, but you are trying to visit pages
route. 关于您的错误,您定义了
pages/index
路径,但是您正在尝试访问pages
路径。
What you can is, is define the pages
route, like: 您可以定义
pages
路由,例如:
get 'pages', to: 'pages#index'
with that, you can visit you page in this way: http://localhost:3000/pages
which will send you to PagesController
and index
action. 这样,您可以通过以下方式访问您的页面:
http://localhost:3000/pages
,它将把您发送到PagesController
和index
操作。
About another error: ExecJS::ProgramError in Pages#index Showing ... 关于另一个错误:Pages#index中的ExecJS :: ProgramError显示...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.