4. Ruby is
object-oriented
dynamic
programming language
simple from outside
Yukihiro
Matsumoto
or “Matz” powerful inside
5. Ruby on Rails
Web applications development framework
Developed in Ruby
Extracted from 37signals Basecamp application
Open source software
Focused on developer productivity
Agile software development approach
6. Main principles
DRY - Don’t Repeat Yourself
Convention over Configuration
Opinionated software
7. MVC Architecture
Request Router Database
Browser
Response
Action Active
Controller Record
Action
View
8. Active Record (Model)
class CreatePosts < ActiveRecor::Migration
def self.up
create_table :posts do |t| CREATE TABLE posts (
t.string :title id NUMBER(38) NOT
t.text :body NULL,
t.timestamps title VARCHAR2(255),
end body CLOB,
end created_at DATE,
end updated_at DATE
);
CREATE SEQUENCE posts_seq;
class Post < ActiveRecord::Base
# nothing here!
end
post = Post.new
post.title = "First post"
post.save
post = Post.find(1)
puts post.name # output: "First post"
9. Action Controller
class PostsController < ApplicationController
def index
@posts = Post.all
end
def show
@post = Post.find(params[:id])
end
def new
@post = Post.new
end
# ...
end
18. Oracle Data Types
Ruby Rails Oracle
Fixnum :integer NUMBER
Float :float NUMBER
BigDecimal :decimal NUMBER, DECIMAL
Time :datetime DATE
Time :time DATE
Date :date DATE
String :string VARCHAR2
String :text CLOB
String :binary BLOB
True/FalseClass :boolean NUMBER(1), CHAR(1)
21. DataMapper Model
class Post
include DataMapper::Resource
property :id, Serial
property :title, String, :length => 255, :nullable => false
property :body, Text
timestamps :at CREATE TABLE posts (
end id NUMBER(38) NOT NULL
PRIMARY KEY,
title VARCHAR2(255) NOT NULL,
created_at DATE,
updated_at DATE
);
CREATE SEQUENCE posts_seq;
CREATE TRIGGER posts_pkt
post = Post.new
...;
post.title = "First post"
post.save
post = Post.get(1)
puts post.name # output: "First post"
22. PL/SQL calls from Ruby
(old way)
require "oci8"
conn = OCI8.new("hr","hr","xe")
cursor = conn.parse <<-EOS
BEGIN
:return := test_uppercase(:p_string);
END;
EOS
cursor.bind_param(':p_string',"xxx",String)
cursor.bind_param(':return',nil,String,4000)
cursor.exec
puts cursor[':return']
cursor.close
25. class Employee < ActiveRecord::Base
set_create_method do
plsql.employees_pkg.create_employee(
:p_first_name => first_name,
ActiveRecord :p_last_name => last_name,
:p_employee_id => nil
)[:p_employee_id]
with end
set_update_method do
PL/SQL plsql.employees_pkg.update_employee(
:p_employee_id => id,
:p_first_name => first_name,
CRUD )
:p_last_name => last_name
procedures end
set_delete_method do
plsql.employees_pkg.delete_employee(
:p_employee_id => id
)
end
end
27. Full-text indexes
add_context_index :posts,
[:title, :body,
# specify aliases always with AS keyword
"SELECT comments.author AS comment_author, " +
"comments.body AS comment_body " +
"FROM comments WHERE comments.post_id = :id" ],
:name => 'post_and_comments_index',
:index_column => :all_text,
:index_column_trigger_on => [:updated_at, :comments_count],
:sync => 'ON COMMIT'
Post.contains(:all_text, "hello")
Post.contains(:all_text, "{first} within title")
Post.contains(:all_text, "{first} AND {post}")
28. Deployment options
Application source
Apache Java app sever
Application WAR file
Ruby mod_passenger
JRuby Gems
Application Application
29. Why Rails on Oracle?
Fast agile / iterative development
Test-driven development support
Flexible HTML/CSS/JavaScript front-end
Easy to put on top of legacy applications
Libraries for all new “cool” technologies
Open-source with liberal license
30. More information
http://blog.rayapps.com
http://github.com/rsim/oracle-enhanced
http://groups.google.com/group/oracle-enhanced
31. Related sessions
Session ID: S318545
Develop a Ruby on Rails Web Application with
Title:
Oracle Database 11g in One Hour
Thursday, September 23, 12:30 | Hilton San
Schedule:
Francisco, Franciscan A / B / C / D
Session ID: S319104
Title: PL/SQL Unit Testing Can Be Fun!
Tuesday, September 21, 09:30 | Hotel Nikko,
Schedule:
Bay View