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 http://127.0.0.1:3000/about it knows which controller to use.

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


Now setup the controller.

app/controllers/home_controller.rb
class HomeController < ApplicationController
def index
# render the landing page
end

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


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: