 
Subject
1 | 2 | >3< | 4 | 5 | 6 | 7 | 8 | 9 | 10
The first thing that Rails does is use the routes.rb to assign a request to a controller. Here is my routes.rb file:
ActionController::Routing::Routes.draw do |map|
map.connect '~borxnat/:action/:id', :controller=>'nat'
map.connect '~borxrssfd/:action/:id.:format', :controller=>'rssfd'
end
|
Notice how I include Commcont. This has all of the code for all controllers. I had a different controller for each domain, but this series of articles just focuses on NetAdminTools.com. I imagine this is quite lame, but I figure if Rails can't figure out how to render the page, that I'll just spit out a 404:
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
rescue_from NameError, :with => :cantdoit
rescue_from ActionView::TemplateError, :with => :cantdoit
rescue_from NoMethodError, :with => :cantdoit
rescue_from ActiveRecord::Rollback, :with => :cantdoit
rescue_from ActiveRecord::StatementInvalid, :with => :cantdoit
rescue_from ActiveRecord::RecordNotFound, :with => :cantdoit
rescue_from ActionController::UnknownAction, :with => :cantdoit
rescue_from ActiveRecord::RecordNotFound, :with => :cantdoit
rescue_from ActiveRecord::StaleObjectError, :with => :cantdoit
rescue_from ActiveRecord::RecordInvalid, :with => :cantdoit
rescue_from ActiveRecord::RecordNotSaved, :with => :cantdoit
rescue_from ActionController::MethodNotAllowed, :with => :cantdoit
rescue_from ActionController::MethodNotAllowed, :with => :cantdoit
rescue_from ActionController::InvalidAuthenticityToken, :with => :cantdoit
def cantdoit
render :text => "
<html>
<body>
Error 404. The file you are looking for is no longer here. Try <a href=\"index.html\">here</a>.
</body>
</html>"
end
include Commcont
end
|
I migrated all sites (at least temporarily as part of my test migration), and it made things easier if all of the controllers were just stubs. The controller for NetAdminTools.com is app/controllers/nat_controller.rb. Here is all it includes:
class NatController < ApplicationController
end
|
Likewise the pages are stubs. Here is app/views/nat/artpage.html.erb:
<%= render 'layouts/artpage.erb' %>
|
The controller for the rss feed is app/controllers/rssfd_controller.rb:
class RssfdController < ApplicationController
def rpage
$realm=params[:id].gsub("articles","")
@articles = Art.find :all, :order => "date DESC", :limit => 25,
:conditions=> {
:realm=>$realm
}
@realmrow = Realm.find(:first, :conditions=> ["name='"+$rname+"'"])
@uresourcerowh = Uresource.find(:first, :conditions=> ["realm='"+$realm+"' AND label='Print Home'"])
end
end
|
The view for my rss feed is app/views/rssfd/rpage.xml.builder:
xml.instruct! :xml, :version => "1.0"
xml.rss :version => "2.0" do
xml.channel do
xml.title @realmrow.shortitle
xml.description @realmrow.longtitle
xml.link @uresourcerowh.tag
for article in @articles
xml.item do
xml.title article.title
xml.pubDate article.date.strftime("%a, %d %b %Y %H:%M:%S GMT")
xml.link @uresourcerowh.tag+"art"+article.artnum.to_s+".html"
xml.guid @uresourcerowh.tag+"art"+article.artnum.to_s+".html"
end
end
end
end
|
1 | 2 | >3< | 4 | 5 | 6 | 7 | 8 | 9 | 10
| People: | |
| Places: | |
| Things: | |
| Times: | |
|
|