Reputation: 5495
I am doing the very intro course in rails, and so far have completed the following
rails new shovell
("shovell" is the name of the app)bundle install
rails generate model Story name link
rails generate controller Stories index
And now when I point to http://localhost:3000/stories
, I get a error that says "Routing Error
No route matches [GET] "/stories" "
And the following is my routes.rb
:
Shovell::Application.routes.draw do
get "stories/index"
# a bunch of comments
end
So I don't know what Im doing wrong, and why its not showing up the default welcome message, but rather giving me an error. Thanks for your help!
Upvotes: 1
Views: 133
Reputation: 9693
However, if you do:
http://localhost:3000/stories/index
you may get the page, although that's not the rails way.
First thing, read and understand the rails routing guide
Then in order to fix your code, on the routing you can write
Shovell::Aplication.routes.draw do
resources :stories
end
Or if you want custom routes instead of a rest resource
Shovel::Application.routes.draw do
match "stores", to: "my_controller#my_action"
end
And you can also name the custom route
Shovel::Application.routes.draw do
match "stores", to: "my_controller#my_action", as: :store_index
end
So with a name you can use the route name on your rails app
link_to("Store Index", store_index_path)
Upvotes: 2
Reputation: 107718
You've defined a route to /stories/index
, but you've not defined one to /stories
, which is why this is failing.
You should define this route like this:
get '/stories', :to => "stories#index"
For more information, see The Routing Guide
Upvotes: 0