简体   繁体   中英

Ruby On Rails - Controller and view blank page

I am stuck and unable to proceed on my Ruby on Rails tutorial.

I am doing a Ruby on Rails tutorial using a mac.

I have created a new Ruby on Rails project in Users/username/sites/simple_cms

I am using Webrick server

I started the server using rails s command and as expected, when navigating to the localhost:3000 the public index page was displayed.

I then added a controller and view using the following command in the route directory:

rails generate controller demo index

The controller and view were successfully created:

My routes file:

SimpleCms::Application.routes.draw do
  get "demo/index"

My demo_controller File:

class DemoController < ApplicationController
  def index
  end
end

My View file is now located in views/demo/index.html.erb :

<h1>Demo#index</h1>

<p>hello world</p>

I then started Webrick again and entered:

http://localhost:3000/demo/index

but a blank page is displayed.

root to 'demo#index'添加root to 'demo#index'以路由文件http://guides.rubyonrails.org/routing.html#using-root

Try to change your route as follows

get "index" => "demo#index"

then you can access the site with localhost:3000/index

But if this is your root path you can also do

root "demo#index"

to access the site with localhost:3000

In this case demo refers to your controller and index to your action in the controller.

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