/
dot-dot
dot
Title: TThier/Languages/ruby/curtHibbs_RWROR.html
Author: Dan Bikle
Sub title and keywords: Ruby on Rails, Mac OS X 10.3.9, Oracle 10g, Ruby 1.8.2
This page discusses my experience with Curt Hibbs web tutorial:
"Rolling with Ruby on Rails"
http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html?page=1
I started by installing Oracle 10g on my Mac.
Good discussions are found here:
http://www.oracle.com/technology/tech/macos/index.html
http://www.oracle.com/technology/pub/articles/rohrer_macosx_10g.html
My env variables:
env.txt
I setup the listener to listen on 127.0.0.1
# listener.ora Network Configuration File: /Users/oracle/OraHome_5/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /Users/oracle/OraHome_5)
(PROGRAM = extproc)
)
(SID_DESC =
(SID_NAME = orcl)
(ORACLE_HOME = /Users/oracle/OraHome_5)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
)
)
I created a simple tns entry in
/Users/oracle/OraHome_5/network/admin/tnsnames.ora:
MOI =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SID = orcl)
(SERVER = DEDICATED)
)
)
From the oracle account, I started the listener with:
lsnrctl start
I created an account for ruby inside of oracle:
biklemac:~/CD/rubyThings/cookbook oracle$ sqlplus
SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jul 17 22:39:28 2005
Copyright (c) 1982, 2004, Oracle. All rights reserved.
Enter user-name: sys/schmyss as sysdba
Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
22:39:45 SQL>
22:39:45 SQL> GRANT dba TO ruby IDENTIFIED BY ruby;
Grant succeeded.
Elapsed: 00:00:00.16
22:40:20 SQL> ALTER USER ruby DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp;
User altered.
Elapsed: 00:00:00.05
22:40:58 SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options
biklemac:~/CD/rubyThings/cookbook oracle$
Next, I installed ruby (notice that I move 1.6 out of the way first):
cd /usr/bin
mv ruby ruby.1.6.8
mv irb irb.1.6.8
download ruby-1.8.2.tar.gz from
http://www.ruby-lang.org/en/20020102.html
tar zxvf ruby-1.8.2.tar.gz
cd ruby-1.8.2
configure
make
make install
make install-doc
cd /usr/bin
ln -s /usr/local/bin/ruby .
With ruby 1.8.2 installed,
I next installed RubyGems:
download rubygems-0.8.11.tgz from
http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz
tar zxfv rubygems-0.8.11.tgz
cd rubygems-0.8.11/
ruby setup.rb
I saw this:
# ruby setup.rb
---> bin
<--- bin
---> lib
---> lib/rubygems
<--- lib/rubygems
<--- lib
---> bin
adjusting shebang: gem_mirror
<--- bin
---> lib
---> lib/rubygems
<--- lib/rubygems
<--- lib
rm -f InstalledFiles
---> bin
...
install version.rb /usr/local/lib/ruby/site_ruby/1.8/rubygems
<--- lib/rubygems
<--- lib
As of RubyGems 0.8.0, library stubs are no longer needed.
Searching $LOAD_PATH for stubs to optionally delete (may take a while)...
...done.
No library stubs found.
Successfully built RubyGem
Name: sources
Version: 0.0.1
File: sources-0.0.1.gem
With rubygems installed,
I next installed Rails:
gem install rails --remote
I saw this:
biklemac:/cd root# gem install rails --remote
Attempting remote installation of 'rails'
Updating Gem source index for: http://gems.rubyforge.org
Install required dependency rake? [Yn] Y
Install required dependency activesupport? [Yn] Y
Install required dependency activerecord? [Yn] Y
Install required dependency actionpack? [Yn] Y
Install required dependency actionmailer? [Yn] Y
Install required dependency actionwebservice? [Yn] y
Successfully installed rails-0.13.1
Successfully installed rake-0.5.4
Successfully installed activesupport-1.1.1
Successfully installed activerecord-1.11.1
Successfully installed actionpack-1.9.1
Successfully installed actionmailer-1.0.1
Successfully installed actionwebservice-0.8.1
Installing RDoc documentation for rake-0.5.4...
Installing RDoc documentation for activesupport-1.1.1...
Installing RDoc documentation for activerecord-1.11.1...
Installing RDoc documentation for actionpack-1.9.1...
Installing RDoc documentation for actionmailer-1.0.1...
Installing RDoc documentation for actionwebservice-0.8.1...
biklemac:/cd root#
Next, I installed ruby-oci8-0.1.11
To do this...
I downloaded ruby-oci8-0.1.11.tar.gz
from here:
http://rubyforge.org/frs/download.php/4607/ruby-oci8-0.1.11.tar.gz
tar zxvf ruby-oci8-0.1.11.tar.gz
cd ruby-oci8-0.1.11/
make
make install
Tested it:
biklemac:/cd/rubyThings oracle$ ruby -r oci8 -e 'OCI8.new("ruby", "ruby", nil).exec("select sysdate from dual") do |r| puts r.join(","); end'
2005/07/17 23:16:53
biklemac:/cd/rubyThings oracle$
I turned to page 2 of Curt's tutorial:
I ran the command:
rails cookbook
I saw this:
biklemac:/cd/rubyThings oracle$ rails cookbook
create
create app/apis
create app/controllers
create app/helpers
create app/models
create app/views/layouts
create config/environments
create components
create db
create doc
create lib
create log
create public/images
create public/javascripts
create public/stylesheets
create script
create test/fixtures
create test/functional
create test/mocks/development
create test/mocks/test
create test/unit
create vendor
create Rakefile
create README
create CHANGELOG
create app/controllers/application.rb
create app/helpers/application_helper.rb
create test/test_helper.rb
create config/database.yml
create config/routes.rb
create public/.htaccess
create config/environment.rb
create config/environments/production.rb
create config/environments/development.rb
create config/environments/test.rb
create script/console
create script/destroy
create script/generate
create script/server
create script/runner
create script/benchmarker
create script/profiler
create script/breakpointer
create public/dispatch.rb
create public/dispatch.cgi
create public/dispatch.fcgi
create public/404.html
create public/500.html
create public/index.html
create public/favicon.ico
create public/javascripts/prototype.js
create public/javascripts/effects.js
create public/javascripts/dragdrop.js
create public/javascripts/controls.js
create doc/README_FOR_APP
create log/server.log
create log/production.log
create log/development.log
create log/test.log
biklemac:/cd/rubyThings oracle$ ls
./ ../ cookbook/ rubygems-0.8.11/ rubygems-0.8.11.tgz
biklemac:/cd/rubyThings oracle$ cd cookbook
biklemac:/cd/rubyThings/cookbook oracle$ ls
./ README components/ doc/ public/ vendor/
../ Rakefile config/ lib/ script/
CHANGELOG app/ db/ log/ test/
biklemac:/cd/rubyThings/cookbook oracle$ ls
./ README components/ doc/ public/ vendor/
../ Rakefile config/ lib/ script/
CHANGELOG app/ db/ log/ test/
biklemac:/cd/rubyThings/cookbook oracle$
I edited and then tested config/database.yml:
development:
adapter:oci
database: orcl
host: orcl
username: ruby
password: ruby
I tried starting the built-in WEBrick web server:
biklemac:/cd/rubyThings/cookbook oracle$ ruby script/server
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:81:in `establish_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:75:in `establish_connection'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:70:in `establish_connection'
from ./script/../config/environment.rb:59
from script/server:42:in `require'
from script/server:42
Bumped into probable bug.
Workaround:
Edit file1:
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/oci_adapter.rb
Some details:
## Bikle debug
## conn = OCI8.new config[:username], config[:password], config[:host]
conn = OCI8.new("ruby","ruby","moi")
## Bikle debug
Edit file2:
config/environment.rb
Some details:
require 'active_support'
require 'active_record'
require 'action_controller'
require 'action_mailer'
require 'action_web_service'
# Environment-specific configuration.
require_dependency "environments/#{RAILS_ENV}"
ActiveRecord::Base.configurations = YAML::load(ERB.new((IO.read("#{RAILS_ROOT}/config/database.yml"))).result)
# Bikle
## ActiveRecord::Base.establish_connection
ActiveRecord::Base.establish_connection(
:adapter => "oci",
:host => "127.0.0.1",
:username => "ruby/ruby@moi",
:password => "ruby",
:database => "moi"
)
# Bikle
I tried starting the built-in WEBrick web server:
biklemac:/cd/rubyThings/cookbook oracle$ !!
ruby script/server
[2005-07-17 23:34:25] INFO WEBrick 1.3.1
[2005-07-17 23:34:25] INFO ruby 1.8.2 (2004-12-25) [powerpc-darwin7.9.0]
[2005-07-17 23:34:25] INFO WEBrick::HTTPServer#start: pid=17233 port=3000
I tried connection:
localhost3000.html
I tried creating a controller:
biklemac:~/CD/rubyThings/cookbook oracle$ ruby script/generate controller bikle10
exists app/controllers/
exists app/helpers/
create app/views/bikle10
exists test/functional/
create app/controllers/bikle10_controller.rb
create test/functional/bikle10_controller_test.rb
create app/helpers/bikle10_helper.rb
I looked at the above files:
biklemac:~/CD/rubyThings/cookbook oracle$ cat app/controllers/bikle10_controller.rb
class Bikle10Controller < ApplicationController
end
biklemac:~/CD/rubyThings/cookbook oracle$ cat test/functional/bikle10_controller_test.rb
require File.dirname(__FILE__) + '/../test_helper'
require 'bikle10_controller'
# Re-raise errors caught by the controller.
class Bikle10Controller; def rescue_action(e) raise e end; end
class Bikle10ControllerTest < Test::Unit::TestCase
def setup
@controller = Bikle10Controller.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
# Replace this with your real tests.
def test_truth
assert true
end
end
biklemac:~/CD/rubyThings/cookbook oracle$ cat app/helpers/bikle10_helper.rb
module Bikle10Helper
end
biklemac:~/CD/rubyThings/cookbook oracle$
Curt said try this; so I did:
http://127.0.0.1:3000/garbage/
Routing Error
Recognition failed for "/garbage/"
http://127.0.0.1:3000/bikle10/
Unknown action
No action responded to index
I built an index method:
biklemac:~/CD/rubyThings/cookbook oracle$ ruby script/generate controller bikle11
exists app/controllers/
exists app/helpers/
create app/views/bikle11
exists test/functional/
create app/controllers/bikle11_controller.rb
create test/functional/bikle11_controller_test.rb
create app/helpers/bikle11_helper.rb
biklemac:~/CD/rubyThings/cookbook oracle$
biklemac:~/CD/rubyThings/cookbook oracle$
biklemac:~/CD/rubyThings/cookbook oracle$ cat app/controllers/bikle11_controller.rb
class Bikle11Controller < ApplicationController
def index
render_text "howdy"
end
end
biklemac:~/CD/rubyThings/cookbook oracle$
http://127.0.0.1:3000/bikle11/
howdy
I did view-source; all I found was "howdy" with no tags at all.
http://127.0.0.1:3000/bikle11/index
gives same thing
I added index10:
class Bikle11Controller < ApplicationController
def index
render_text "howdy"
end
def index10
render_text "howdy twice"
end
end
http://127.0.0.1:3000/bikle11/index10
gives
"howdy twice"
Next, I created some tables:
23:46:12 SQL> set lines 55
23:46:22 SQL> desc CATEGORIES
Name Null? Type
-------------------------- -------- ------------------
ID NUMBER(10)
NAME VARCHAR2(55)
23:46:28 SQL> desc RECIPES
Name Null? Type
-------------------------- -------- ------------------
ID NUMBER(10)
TITLE VARCHAR2(55)
DESCRIPTION VARCHAR2(55)
CREATED DATE
INSTRUCTIONS VARCHAR2(3999)
CATEGORY_ID NUMBER(10)
23:46:35 SQL>
Also I created a sequence:
SQL> CREATE SEQUENCE rails_sequence;
Sequence created.
I then walked through the rest of Curt's tutorial.
Everything worked as advertised.
On page 5 of the tutorial,
one of his .rhtml pages had a bug/typo:
bad: if category.id == @recipe.category.id
good: if category.id == @recipe.category_id
Although much of the information gathered here is for Mac OS X,
it might be useful for someone wanting to walk through the tutorial
with a Linux or Solaris box.
Also the hack I did to
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/oci_adapter.rb
might be of use to users of DB2, Sybase, and PostgreSQL.
2005-09-05 Note/Addition
Edge Rails has a recent enhancement added to it which is related to Oracle
and its use of sequences.
The idea behind the enhancement is simple; instead of using just one sequence
named 'rails_sequence' for the entire application,
we use one sequence per table. This of course requires that we establish
a naming convention for the sequences.
For example if we have a table named 'rocks' the corresponding sequence
would be called 'rocks_seq'.
The syntax behind rocks_seq would be:
CREATE SEQUENCE rocks_seq;
Give me a holler if you have any questions about this:
bikle@bikle.com
Here is some more info:
http://dev.rubyonrails.com/ticket/1798
-Dan
|