I want to create static web pages in my App - T&Cs, About, Privacy etc... I could just create blank pages and put them in the public folder and put 'href' links to them. Is this considered best practice? or should I use rails g controller for each of them? What's the difference...
HighVoltage is a gem that helps out with exactly what you're taking about:
https://github.com/thoughtbot/high_voltage
It makes it really easy to handle these scenarios. From the docs:
Write your static pages and put them in the RAILS_ROOT/app/views/pages directory.
$ mkdir app/views/pages
$ touch app/views/pages/about.html.erb
After putting something interesting there, you can link to it from anywhere in your app with:
link_to "About", page_path("about")
This will also work, if you like the more explicit style:
link_to "About", page_path(:id => "about")
Oftentimes I will make a site
controller that has actions for each of the public pages, assuming there isn't going to be a ton of content on the public side. If there was more, I would look into some kind of CMS. Anyway, create a site
controller, and then create routes and templates for each of the pages you need. That way you'll be able to use a layout, and use Rails helpers if you need them.
Sure, you can just create about.html
, etc and put them into the public
folder. If it's just a completely static web page, then the controller adds no value. Subdirectories also work just fine in the public
folder, as you would expect.
I solved it by using this awesome GEM https://github.com/thoughtbot/high_voltage
Just dawned me that this should actually be quite easy, hopefully, think this through:
Create a route like for example:
match '/about' => "static#about"
~ then create a simple controller, in this case app/controllers/static_controller.rb
class StaticController < ApplicationController
respond_to :html
def about
# nuttin
end
end
~ now all we need is a view: ( /app/views/static/about.html.erb )
Hey!
Sorted
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