DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

About Controller

08.19.2005
| 582 views |
  • submit to reddit
        This controller will load the appropriate template if it exists, or display a 404 page if not.

class AboutController < ApplicationController
  def index 
    unless @params["id"].nil?
      if File.exists? "app/views/about/#{@params["id"]}.rhtml"
        render(:template => "about/#{params["id"]}", :layout => true)
      else
        render(:template => "about/404", :status => 404, :layout => true)
      end
    else
      render(:template => "about/index", :layout => true)
    end
  end
end
    

Comments

Snippets Manager replied on Mon, 2012/05/07 - 2:14pm

You can route to this using map.connect 'about/:id', :controller => "about", :action => "index", :id => "index"