Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails3 - Create A Static Web Page?

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...

like image 902
ubique Avatar asked May 10 '11 01:05

ubique


5 Answers

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")
like image 178
brendan Avatar answered Nov 15 '22 10:11

brendan


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.

like image 40
Austin Taylor Avatar answered Nov 15 '22 11:11

Austin Taylor


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.

like image 29
mharper Avatar answered Nov 15 '22 09:11

mharper


I solved it by using this awesome GEM https://github.com/thoughtbot/high_voltage

like image 36
lajlev Avatar answered Nov 15 '22 09:11

lajlev


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

like image 34
flunder Avatar answered Nov 15 '22 09:11

flunder