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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With