By Rupert
ruby on rails
Rails Note #5: Dynamic Layouts
Nov 13th
Wow.. everyday.. Ruby on Rails seems to amuse me.. I just figured how to seperate layouts just by having different files in the layouts/ which corresponds to a controller. If a layout file “home (home.html.erb)” exists and there is home_controller, then the home_controller would use that layout instead of application.html.erb.
Now.. I haven’t validated this concept by book and would do so soon..

Fig 1
Another way is specifying a filter…
1. In application.rb, specify a method that displays the ‘admin’ layout if the user is admin.
def load_layout if admin? self.class.layout('admin') end end
2. home_controller
class HomeController < ApplicationController before_filter :load_layout end

Fig 2. admin.html.erb now exists in layouts/
Reference:
http://railscasts.com/episodes/125-dynamic-layouts
Rails Note #4: Deploying a Rails Application in a Subdirectory
Nov 7th
There are many ways to deploy RoR applications. I have googled all over the place and so far the easiest setup that I could find that would suit my needs (existing Apache2 + ColdFusion + TileCache) would be to use
1. Apache PROXY
2. Mongrel
CentOS Installation Instructions
1. Make sure Apache has mod_proxy
./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --with-mpm=prefork --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-httpd --enable-proxy-ajp --enable-proxy-balancer --enable-cgi
1. Apache Proxy
<VirtualHost *:80>
ServerName test
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /localdumplings http://localhost:3000/localdumplings
ProxyPassReverse /localdumplings http://localhost:3000/localdumplings
#ProxyPass /localdumplings/ http://localhost:3000/
#ProxyPassReverse /localdumplings/ http://localhost:3000/
</VirtualHost>2. Starting mongrel on a subdir
mongrel_rails start –prefix=/localdumplings
Debian Installation Instructions
1. Install libapache2-mod-proxy-html is easier…
sudo apt-get install libapache2-mod-proxy-html
2. Enable modules to load in apache2
sudo a2enmod proxy sudo a2enmod proxy_balancer sudo a2enmod proxy_http sudo a2enmod rewrite sudo /etc/init.d/apache2 stop sudo /etc/init.d/apache2 start
3. Add the application in /etc/apache2/mods-available/proxy.conf
<IfModule mod_proxy.c>
#turning ProxyRequests on and allowing proxying from all may allow
#spammers to use your proxy to send email.
ProxyRequests Off
<Proxy *>
AddDefaultCharset off
Order deny,allow
Allow from all
#Allow from .example.com
</Proxy>
# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off | On | Full | Block
ProxyPass /localdumplings http://localhost:3000/localdumplings
ProxyPassReverse /localdumplings http://localhost:3000/localdumplings
ProxyVia On
</IfModule>Starting a mongrel_rails on boot
Slicehost ( http://articles.slicehost.com/2007/9/21/debian-etch-apache-vhosts-rails-and-mongrels ) has a very good article regarding this.
mongrel_rails start -d -e production -p 8001 -P log/mongrel8001.pid -l log/mongrel.log
Rails Note #3: Installing Footnotes for RAILS
Nov 5th
1. Install GIT from http://code.google.com/p/git-osx-installer/
2. http://josevalim.blogspot.com/2008/05/footnotes-v30.html – Jose Valim is now maintaining footnotes
3. How to install?
cd myapp/vendor/plugins git clone git://github.com/drnic/rails-footnotes.git footnotes rm -rf footnotes/.git
In summary, you are better off installing the plugin from GIT instead of SVN if you are using rails 2.1.x or edge ( at the time this post was written)
UPDATE
If you are receiving 500 Internal Server Error when having errors on your views then please read below..
If you are running on Rails 2.1.x, you should use Footnotes v3.2.2:
cd myapp git clone git://github.com/drnic/rails-footnotes.git vendor/plugins/footnotes cd vendor/plugins/footnotes git checkout v3.2.2 rm -rf ./.git
If you are running on Rails 2.0.x or Rails 1.x, you should use Footnotes v3.0:
cd myapp git clone git://github.com/drnic/rails-footnotes.git vendor/plugins/footnotes cd vendor/plugins/footnotes git checkout v3.0 rm -rf ./.git
Remember that in Rails 1.x, after filters appear first than before filters in the Filters tab.
Rails Note #2: Links
Nov 2nd
Ruby References
Ruby Quick Reference
http://www.zenspider.com/Languages/Ruby/QuickRef.html
Rails References
Downloadable Rails API with Javascript http://www.railsbrain.com/ (Preferred)
Official Rails API http://api.rubyonrails.org/
GotAPI
http://www.gotapi.com/html
Naming Conventions
RubyOnRails Naming Conventions from ITSignals
http://itsignals.cascadia.com.au/?p=7
RubyOnRails.org TipSheetForBeginners
http://wiki.rubyonrails.org/rails/pages/TipSheetForBeginners
Tutorials
AkitaOnRails: Rails 2.0 First Full Tutorial
http://www.akitaonrails.com/2007/12/12/rolling-with-rails-2-0-the-first-full-tutorial
Blogs
AkitaOnRails
http://www.akitaonrails.com
Books
The Ruby Way
http://rubyhacker.com/
Rails Note #1: Getting my feet wet in Ruby On Rails
Nov 2nd
1. Just installed Ruby and Rails on my MacOSX Leopard. The current version of rails is 1.2.6. I wanted to upgrade using gem update –system but it seems like taking forever.. So I did a manual install of ruby, rubygems then rails..
2. The tutorial that I followed was from http://hivelogic.com/articles/2008/02/ruby-rails-leopard
Installation Summary
2.1 ruby
wget http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p286.tar.gz tar -zxvf ruby-1.8.6-p286.tar.gz ./configure make make install
2.2 rubygems
wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz tar -zxvf rubygems-1.3.1.tgz ruby setup.rb
2.3 rails
gem install -V rails
2.4 other gems
gem install rubygems-update gem install mongrel gem install capistrano gem install postgres gem install builder
3. Browsed the first few pages of the hilarious http://www.poignantguide.net/ruby
4. Went for a book. Found Simply Rails 2.0 on Boox24x7 and Safari. Added that to my shelf and read chapters 1 – 5 on my first night.
5. Was able to setup database configuration in config/database.yml using Postgres. I have yet to study how oracle works.
6. rake db:migrate is a convenient way of building your database schema without using SQL. Simply Rails 2.0:Chapter 5:Generating a Model introduced inserting records using script/console
7. URL Helpers for Story Resource
stories_path /stories
new_story_path /stories/new
story_path(@story) /stories/1
edit_story_path(@story) /stories/1/edit
Remember to define the route in config/routes.rb
map.resources :users, :categories
8. Naming Conventions

Variables – lowercase letters and words separated by underscores.
i.e name, country_of_origin
DB Table and Column names should follow convention is always pluralised.
i.e users
Classes and Modules – no underscores and each word is capitalized
i.e User, UserCategories
Comments