Phil
Phil

Reputation: 57

generate routes for one page landing pages?

I am attempting to build a simple webpage using Rails and this guide to great looking landing pages by William Ghelfi (thanks!) http://www.williamghelfi.com/blog/2013/08/04/bootstrap-in-practice-a-landing-page/

I have started a new project on rails using Rails 4.0.0

Server is running fine on localhost:3000 as evidenced by the RoR landing page.

My question is what's the best way to generate routes and controllers for a one page landing page using RoR?

Right now, when I attempt to point to localhost:3000/lpd.html I get the error No route matches [GET] "/lpd.html" No routes defined.

Upvotes: 2

Views: 2017

Answers (1)

nathanvda
nathanvda

Reputation: 50057

If you just want a static page, you can just move the lpd.html to the public folder and it will work. But many rails websites have semi static pages.

So you could create a LandingController or HomeController where you keep all your semi-static pages. E.g. home, about, contact us ...

So for instance, do the following

rails g controller Home index about

This will generate a HomeController with two actions index and about, with the corresponding views and default routing. So in app/views/home two views will be added, which you can then edit as you wish.

Then you can edit the routing (in config/routes.rb) as follows:

get '/about' => 'home#about'
root_to 'home#index'

This will make sure that http://localhost:3000 will be your home/index view, and http://localhost:3000/about will be your about page.

Upvotes: 5

Related Questions