Ruby on Rails All Hands Meeting

26
Ruby on Rails, Apache httpd, and Oracle Dan Davis [email protected] B1N14Q

description

Presentation on Ruby on Rails at a ColdFusion Oracle shop.

Transcript of Ruby on Rails All Hands Meeting

Page 1: Ruby on Rails All Hands Meeting

Ruby on Rails, Apache httpd, and Oracle

Dan [email protected]

B1N14Q

Page 2: Ruby on Rails All Hands Meeting

Overview

Why this Talk? Ruby on Rails Fast prototyping (demo) Integrating with Apache httpd Integrating with Oracle Maybe demo

Page 3: Ruby on Rails All Hands Meeting

Why this Talk?

Node.js, MongoDB, and Express were cool Lots of Rapid Prototyping Environments

• Ruby on Rails (Digital Collections)• ColdFusion (many things)• php (Cake)

Secure, Reliable, Transparent Data Integration

Page 4: Ruby on Rails All Hands Meeting

Why Ruby on Rails?

How I started: a great application MVC

• Rapid prototyping• Separation of Concerns• Generators

Unit and Integration Testing Security is built-in Community Library of “gems”

Page 5: Ruby on Rails All Hands Meeting

Ruby Overview

General Purpose Innovative Class and Object model Domain Specific Languages Lamdas (function objects), Blocks, and Mixins JRuby

Page 6: Ruby on Rails All Hands Meeting

Class and Object model

•Everything is an Object•Module – namespace, interface, behavior•Class – inheritance, instantiation

Page 7: Ruby on Rails All Hands Meeting

Ruby - Domain Specific Languages

Implicit Hash, no parentsdoit first, second, :k1 => v1, :k2 => v2doit first, second, k1: v1, k2: v2

Comes from Functional Programming(FORTH, Tcl, Ruby, Python)

Examples Today• Gemfile• Routing• Rspec Tests (BDD)

Page 8: Ruby on Rails All Hands Meeting

Ruby - Lambdas and Blocks

Lambdas – function objectsl = lambda ( “There is no try” )Puts l.call

Blocks – are implicit argumentsdef implicit_block(number) puts yield(number)endimplicit_block(7) { |number| number + 1 }

Blocks – sometimes explicitdef explicit_block (number, &block)

Page 9: Ruby on Rails All Hands Meeting

Ruby - Mixins

Can include a moduleclass AccountController

include AccountHelpers…

Can extend a modulebar = Bar.newbar.extend Foo

Can re-open objectsclass Stringdef empty? end

Changes API Design

Page 10: Ruby on Rails All Hands Meeting

Ruby - jruby

ruby is like perl – C with links to libs jruby is JVM implementation jruby starts slow, gets fast Not quite transparent

• Some “gems” implemented differently• Some “gems” not available• Cannot call SWT/Swing from ruby!• Higher bar to start

Page 11: Ruby on Rails All Hands Meeting

Rails - Generators

Applicationrails new demoapp

Modelrails generate User name:string \ email:string password_hash:string

Migrationrails g migration AddRoleToUser

Controllerrails g controller Users all view edit

Integration Testrails g integration_test AccountSettings

Page 12: Ruby on Rails All Hands Meeting

Ruby - Gemfile

Tracks dependencies (like Ivy, Maven) Example of Domain Specific Language Easy

# Use jquery as the JavaScript librarygem 'jquery-rails', '~> 3.1.0'gem 'jquery-datatables-rails'

Page 13: Ruby on Rails All Hands Meeting

Rails - Routing

config/routes.rbNedtable::Application.routes.draw do

get ‘users’, to: ‘users#all’post ‘users’, to: ‘users#create’get ‘users/:id’, to: ‘users#view’get ‘users/:id/edit’, to: ‘users#edit’post ‘users/:id’, to: ‘users#update’

end See it in web See it on the console

Page 14: Ruby on Rails All Hands Meeting

Rails - rspec

Behavioral Driven Testing Easy to read

describe MarcExporter doit { should respond_to :to_marc }it { should respond_to :reader }…

describe "for NLM UI 1589530" do…its(:to_xml) { should == xmldata }its(:to_marc) { should == mrcdata }

end “Mock” network connections

Page 15: Ruby on Rails All Hands Meeting

Rails - security

CSRF• automatically adds to form• Automatically checks

Injection• You never have to write SQL• Automatically wraps SQL/XML

CSS - Safe by default<%= “<br/>”.html_safe() %>

Page 16: Ruby on Rails All Hands Meeting

Rails - So much more

Asset Pipeline Layouts Engines “gems” and more “gems”

Page 17: Ruby on Rails All Hands Meeting

Why Apache2? Why Oracle?

Good Tools give you: Shoulders to stand on (powerful abstractions) Without compromising flexibility

Good Architecture: Same thing at Project level

Good Standards: Same thing at Organizational Level

Page 18: Ruby on Rails All Hands Meeting

Apache2 - Context

Page 19: Ruby on Rails All Hands Meeting

Apache2 – nlm.conf<Location /solr>

ProxyPass ajp://localhost:8009/solrProxyPassReverse ajp://localhost:8009/solrOptions -MultiViewsOrder allow,denyAllow from 130.14.160.225/24

AuthType CASAuthName "NLM Login"CASScope /Require user davisda4 butlerj pantrCASAuthNHeader REMOTE_USER

</Location>

Page 20: Ruby on Rails All Hands Meeting

Oracle - Benefits

Reliable Secure XMLDB is included Transparent – SQL Developer/Toad Oracle Support in OSS evaluation

• Measures maturity• Measures Enterprise readiness

Page 21: Ruby on Rails All Hands Meeting

Oracle – link to Rails Gemfile

gem 'ruby-oci8', '~> 2.1.0'gem 'activerecord-oracle_enhanced-adapter’

config/database.ymldevelopment:

adapter: oracle_enhanceddatabase: 'oltp01_dev'username: 'discovery'password: ‘cleartext’

Integrating getDBPasswordpassword: <% `getDBPassword …` %>

Multiple Databasesestablish_connection :serials

Page 22: Ruby on Rails All Hands Meeting

Let’s Build Something

ER Diagram

Navigational State Diagram

Page 23: Ruby on Rails All Hands Meeting

Cheat sheet #1

Create Applicationrails new allhands –Tcd allhands

Update Gemfile and get dependenciesvim Gemfilebundle updatebundle install

Integrate dependencies through generatorsrails g devise:installrails g active_admin:installrake db:migrate

Page 24: Ruby on Rails All Hands Meeting

Cheat sheet #2

Create Modelsrails g model Person …rails g model OrgUnit …rake db:migraterails g active_admin:resource Personrails g active_admin:resource OrgUnit

Fix Saving the Data Fix “associations”, e.g. foreign keys Add graphviz integration How much code did I write?

Page 25: Ruby on Rails All Hands Meeting

Takeaways - Learning

Ms. Frizzle• Make mistakes• Try things• Get messy

Learning is Fun• Cold Fusion MVC frameworks?• Call Java libraries from CFML?• Call jruby libs from CFML?

Page 26: Ruby on Rails All Hands Meeting

Questions?