NetAdminTools.com
 
SignalQ Sites:
NetAdminTools - Coprolite - SpotBridge - NAW
RoboCoop - AreWeDown - SolarPower - SysAdminTools
Xfig - Gold Loaf - GeekPapa - FixGMC - FixRambler
Categories:
GNU/Linux | Homebrew designs | Perl | Ruby | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | ERP | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | GNU/Linux Reference OS Build | MCJ How-to | Keywords | RSS



Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Ruby
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·ERP
·REALbasic
·All Categories


Ruby on Rails Migration - Part 3 - Rails Configuration
Topic:Ruby   Date: 2010-01-05
Printer Friendly: Print

spacerspacer
<<  <   >  >>

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:





Please read our Terms of Use and our Privacy Policy
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2010 NetAdminTools.com