Reputation: 3
I am having some difficulty figuring out how to route static pages in rails 4. I have created a controller called PagesController
and so I also have a views folder called pages
with the oakville.html.erb file in it.
My controller looks like this:
class PagesController < ApplicationController
def our_mission
end
end
My routes file looks like this:
get "oakville", :to => "pages#oakville"
I am assuming that I should be able to get to this page by going to localhost:3000/oakville ??
Upvotes: 0
Views: 705
Reputation: 1124
The methods in your controller are called actions, and for each static page that you want to be able to navigate to you will need a corresponding controller action. When a person (or link) navigates to yoursite/oakville
your routes file needs to know which controller action to perform for the oakville branch of the url.
In the routes that you have shown, get "oakville", :to => "pages#oakville"
you are asking the controller to render the oakville
action. But there is no oakville
action in your controller. Add one and problem solved:
class PagesController < ApplicationController
def our_mission
end
def oakville
end
end
Upvotes: 0
Reputation: 41954
Yes, but you need to add a controller action for oakville
class PagesController < ApplicationController
def oakville
end
end
Also, you will need to create oakville.html.erb
and put this into your views/pages
directory
Upvotes: 1
Reputation: 239521
The route you've shown and the action you've shown are completely unrelated.
If you want to route a url like http://www.example.com/oakville
to an action called our_mission
on the Pages
controller, the route looks like this:
get 'oakville' => 'pages#our_mission'
What you've written indicates you expect an action called oakville
to exist, and according to the code you've provided, it doesn't.
Upvotes: 0