简体   繁体   中英

Rails 4 newbe : Routing Error -

I am very new to rails. No idea how to fix it. I cannot even start a simple rails app!

Environment:
    Windows 7
    Ruby 2.1.0
    Rails 4.2.3

First: I ran generate command

D:\\railprojects\\blog>rails generate controller Pages index

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>

I am getting following error.

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

Please help. If you need more info, please let me know.

localhost:3000/pages/index

changed to - get '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

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

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:

get 'pages', to: 'pages#index'

You can find more about Rails routing here ;

Good luck!

UPDATE

The whole content of config/routes.rb should look like:

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. Believe in me.

If you dont want to install Linux (like ubuntu), you can use vagrant ( https://www.vagrantup.com/ ).

About your error, you defined pages/index route, but you are trying to visit pages route.

What you can is, is define the pages route, like:

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.

About another error: ExecJS::ProgramError in Pages#index Showing ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM