Nerdysyntax
Nerdysyntax

Reputation: 365

routing a different root index

I am new to rails and want to do a simple routing to root operation. My file path is app/views/slots/index.html.erb. When I go in my routes.rb file and see:

You can have the root of your site routed with "root"
just remember to delete public/index.html.
root :to => 'welcome#index'

I change the 'welcome#index' to "slots#index', I get this error from localhost:3000:

No route matches [GET] "/"

In the terminal, I use ctrl c to exit server and $ rails server to restart and still get the error. I watched my instructor do the same exact simple steps yet I get this error. Anyone know what I did wrong?

Upvotes: 0

Views: 397

Answers (1)

Thomas Guillory
Thomas Guillory

Reputation: 5729

Edit : my bad, indeed the error is not corresponding to the solution I described below.


It seems you didn't create the slots controller.

You have to create a controller to display files. app/views/slots/index.html.erb is just a view, corresponding to an action of a controller.

So create the file app/controller/slots.rb class SlotsController < ApplicationController def index end end

You can do this faster with generator. In your terminal, cd to your application path and then rails generate controller Slots index

To learn Rails I recommend you some reading here : http://guides.rubyonrails.org/getting_started.html

Upvotes: 1

Related Questions