By Rupert
ruby
Rails Note #12: Oracle on Intel Mac
Dec 5th
2. Install Oracle Instant Client on Mac.
a. Instant Client Package – Basic: All files required to run OCI, OCCI, and JDBC-OCI applications
- instantclient-basic-macosx-10.2.0.4.0.zip (34,020,719 bytes)
b. *Instant Client Package – SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client
instantclient-sdk-macosx-10.2.0.4.0.zip (603,493 bytes)
OR download the whole bundle (10.2.0.4.zip) with sqlplus installed from my installers.
3. Put this on your sudo vim ~/.bash_profile.
export ORACLE_HOME=/Library/Oracle/instantclient/10.2.0.4 export TNS_ADMIN=$ORACLE_HOME export LD_LIBRARY_PATH=$ORACLE_HOME export DYLD_LIBRARY_PATH=$ORACLE_HOME export PATH=$PATH:$ORACLE_HOME
4. Make a symbolic link
cd /Library/Oracle/instantclient/10.2.0.4 ln -s libclntsh.dylib.10.1 libclntsh.dylib
5. Go to /Library/Oracle/instantclient/10.2.0.4 and edit tnsnames.ora. Point the Oracle SID to the IP where you installed Oracle.
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.155)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
ORCL_2_11 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.11)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)6. Install the oracle-adapter for rails
sudo gem install activerecord-oracle-adapter --source http://gems.rubyonrails.org
7. In your database.yml file
development: adapter: oracle database: orcl username: youzhu_mobile_dev password: your_password
or browse the contents of a sample rails project youzhumobile.tar.gz
8. If you ever encounter an encoding problem, then we need to set the NLS_LANG environment variable before running script/server.
# export NLS_LANG=American_America.UTF8 # script/server
or I prefer setting it in the environment.rb
Rails::Initializer.run do |config| ENV['NLS_LANG']='American_America.UTF8' # Settings in config/environments/* take precedence over those specified here.
Note: If you don’t know your database encoding, then read this post.
Rails Note #6: Pagination
Nov 16th
1. will_paginate docs
Main http://github.com/mislav/will_paginate/wikis
Reference http://mislav.uniqpath.com/static/will_paginate/doc/
Clone URL: git://github.com/mislav/will_paginate.git
2. Installation as a gem
http://github.com/mislav/will_paginate/wikis/installation
gem sources -a http://gems.github.com
Once installed, do script/server
3. Controller
class PoiAppController < ApplicationController def poi_by_category mylimit = 100 sql = "SELECT pa.* FROM poi_apps pa WHERE pa.id IN " + "(" + "SELECT pc.poi_app_id " + "FROM poi_categories pc " + "WHERE pc.categ_node_id LIKE '" + params[:node_id] + "%%'" + "LIMIT " + mylimit.to_s + ")" #@poi_apps = PoiApp.find_by_sql(sql) @poi_apps = PoiApp.paginate_by_sql [sql], :page => params[:page], :per_page => 10 end end
4. View
<h2>POIs</h2>
<div clas="page_info">
<%= page_entries_info @poi_apps %>
</div>
<table>
<tr>
<td>POI_APP_ID</td>
<td>CN_NAME</td>
<td>EN_NAME</td>
</tr>
<% for poi in @poi_apps %>
<tr>
<td><%= poi.id %></td>
<td><%= poi.cn_name %></td>
<td><%= poi.en_name %></td>
</tr>
<% end %>
</table>
<%= will_paginate @poi_apps %>5. Checkout the styles http://mislav.uniqpath.com/static/will_paginate/
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