Aleksandr Sinkevič
Aleksandr Sinkevič

Reputation: 327

Ruby On Rails "Hello World" page doesn't work

I'm new in ruby on rails and I have a problem. When I starе server " rails server and going to the page www.localhost:3000 in my browser everything works fine with ROR default page, but.... after making controller rails generate controller demo index and going to the page www.localhost:3000/demo/index , localhost:3000/demo - the same - there is nothing, seems like page doesn't exist, only a blank page. I tried to change index.html.erb code <h1>Hello World</h1> - no change. I want to practice with ROR, but can't because of that bug.

Work environment: Windows 7 64-bit

Database: MySQL

Upvotes: 0

Views: 1115

Answers (8)

mimsugara
mimsugara

Reputation: 879

As indicated by João there, you will also need a view for that. Additionally, delete public/index.html and finally add a route for your controller.

If you had created a scaffold Rails start guide you would already have the route there for you.

Upvotes: 0

Richard Jordan
Richard Jordan

Reputation: 8202

Have you deleted

app_root
--public
----index.html

yet?

Rails will look in the public folder first for a matching file before it will goto build one from your views.

Upvotes: 0

RahulOnRails
RahulOnRails

Reputation: 6542

First of all delete or rename the index.html file from public folder.

Then set root :to => 'demo#index' at route file.

Then restart the server by using this command. rails s by default your server will run at port 3000.

Now simply type http://localhost:3000/ or http://localhost:3000/demo/index

Upvotes: 0

Raj Adroit
Raj Adroit

Reputation: 3888

Uncomment this line from your config/routes.rb file

  match ':controller(/:action(/:id))(.:format)'

Remove index.html file from public/index.html

Upvotes: 0

hypee
hypee

Reputation: 718

check your routes.rb

root :to => 'demo#index'

Go to http://localhost:3000/

Upvotes: 0

Jon
Jon

Reputation: 2793

make sure

views/layout/application.html.erb has yield and index.html.erb have some text

Upvotes: 0

Jo&#227;o Daniel
Jo&#227;o Daniel

Reputation: 8986

You need to have a view corresponding to your action.

If your controller is called Demo and your action is index it should be

# app/controllers/demo_controller.rb
class DemoController < ApplicationController

  def index
  end

end

and the view file should be at app/views/demo/index.html.erb.

Upvotes: 1

Richard Brown
Richard Brown

Reputation: 11444

The index action is the base action of the controller. Try just:

http://localhost:3000/demo

to access the index.

By default routes /demo/index is the show action with the id of index.

Upvotes: 0

Related Questions