1

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 https://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
Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89
Khoga
  • 857
  • 2
  • 8
  • 26
  • 1
    you should replace existing line with this in your routes file `get 'pages/', to: 'pages#index` – Athar Aug 11 '15 at 07:53
  • For ExecJS error , take a look at [this](http://stackoverflow.com/questions/12520456/execjsruntimeerror-on-windows-trying-to-follow-rubytutorial) , – dreamingblackcat Aug 11 '15 at 15:38

3 Answers3

1

try

localhost:3000/pages/index

or if you want to go on index page with this localhost:3000/pages change routes

resources :pages
Sajjad Murtaza
  • 1,444
  • 2
  • 16
  • 26
  • Hi, changes that but still shows error. Due to stackoverflow rule I could not attached the screen shot but here is the error. 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 – Khoga Aug 11 '15 at 08:14
0

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
Paweł Dawczak
  • 9,519
  • 2
  • 24
  • 37
  • Hi, Thanks for reply. But it still shows error 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 – Khoga Aug 11 '15 at 08:06
  • Hi, changed it to get pages#index, but still shows error 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 – Khoga Aug 11 '15 at 08:18
  • @Khoga, it's very difficult to read the stack trace from comments, could you update your question with this information? – Paweł Dawczak Aug 11 '15 at 08:19
  • Ok, my apologies @Khoga, I'm afraid I've confused you a bit... Please check my answer updated, so you can find the content of whole `config/routes.rb` – Paweł Dawczak Aug 11 '15 at 08:26
0

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 pagesroute, like:

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

with that, you can visit you page in this way: http://localhost:3000/pageswhich will send you to PagesController and index action.

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

WeezHard
  • 1,982
  • 1
  • 16
  • 37
  • Hi, did that as Pawel suggested. no luck. Seems I have to install Ubuntu! – Khoga Aug 11 '15 at 08:42
  • @Khoga did restart the server after install NodeJS ? maybe you need to restart Windows too – WeezHard Aug 11 '15 at 08:53
  • Hi, how to install nodejs? gem install nodejs ?? – Khoga Aug 11 '15 at 09:57
  • Installed Rails on Ubuntu and everything fine! not going to to use Windows.A huge thanks to @Paweł Dawczak. Sorry I could not mark both of you correct. – Khoga Aug 12 '15 at 00:06