Twitter Updates

Sunday, 11 October 2009

Rails Simple Pages

Ruby on Rails good for handling data models and folowing an MVC framework but there seems to be a lack of documentation for adding simple pages, I did find asmallguide on the has_many :through blog
with only a few omissions that some one new to rails might not know.

First setup the routes so that when entering it knows which controller to use.

 map.root :controller => 'home'
map.home ':page', :controller => 'home', :action => 'show', \
:page => /about|contact/

Now setup the controller.

class HomeController < ApplicationController
def index
# render the landing page

def show
render :action => params[:page]

Now create the 'home' folder. so we have a apps/views/home to put about.html or about.html.erb in.

Linking to this page can now be don via:
 link_to 'About', home_path('about') 

This tutorial was very closely based on 'Has many :through simple pages'

No comments: