我对rails很新。不知道如何解决它。我甚至无法启动一个简单的rails应用程序!
Environment:
Windows 7
Ruby 2.1.0
Rails 4.2.3
首先:我运行了生成命令
D:\ railprojects \ blog> rails生成控制器页面索引
的routes.rb
Rails.application.routes.draw do
get 'pages/index'
end
pages_controller.rb
class PagesController < ApplicationController
def index
end
end
index.html.erb
<h1>Pages#index</h1>
<p>Find me in app/views/pages/index.html.erb</p>
我收到了以下错误。
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
截图 http://i.stack.imgur.com/06W5e.jpg
请帮忙。如果您需要更多信息,请告诉我。
本地主机:3000 /页/索引
更改为 - 获取&#39;页面#index&#39;
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
将其更改为 - 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
更改为
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
答案 0 :(得分:1)
尝试
localhost:3000/pages/index
或者如果你想使用这个localhost进入索引页面:3000 / pages更改路由
resources :pages
答案 1 :(得分:0)
你应该指出
http://localhost:3000/pages/index
在浏览器中进行正确的操作。
这是因为您的路线配置:
get 'pages/index'
如果您希望能够指向/pages
,则必须将其重新配置为:
get 'pages', to: 'pages#index'
您可以找到有关Rails路由here;
的更多信息 祝你好运!<强>更新强>
config/routes.rb
的全部内容应如下所示:
Rails.application.routes.draw do
get 'pages', to: 'pages#index'
end
答案 2 :(得分:0)
首先,不要使用Windows来开发Rails ......你会有很多麻烦。相信我。
如果您不想安装Linux(如ubuntu),可以使用vagrant(https://www.vagrantup.com/)。
关于您的错误,您定义了pages/index
路线,但是您尝试访问pages
路线。
您可以定义pages
路线,例如:
get 'pages', to: 'pages#index'
通过这种方式,您可以通过以下方式访问您的网页:http://localhost:3000/pages
,它会将您转到PagesController
和index
行动。
关于另一个错误:页面中的ExecJS :: ProgramError #index显示...