Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help creating a route and controller for static pages

I have some static pages I am trying to make like team, aboutUs, terms of service, etc.

I am trying to make one controller to handle the static pages, but I am missing some know-how.

Here is what I did:

In routes.rb, before the end I added this:

match "/:action" => "pages"

Then I made a controller named pages_controller.rb

Currently it is empty. What I need it to do is recognize the requests like /pages/team or pages/about_us and redirect to the right static page. How can I do that?

Thank you!

like image 446
GeekedOut Avatar asked May 24 '11 23:05

GeekedOut


1 Answers

This is how I do it:

match '/pages/:page' => "pages#page"

Then based on params[:page] i render different static views. This works good for me, for sites with a smaller number of static pages.

Of course you can explicitly name your routes:

match '/about-us' => "pages#about_us"

and then declare an empty method for each route in your Pages controller:

def about_us
end

but I prefer the first way.

like image 198
Mirko Avatar answered Oct 18 '22 12:10

Mirko