Ruby on Rails
HowToRailScotTiger

What I’d like to see is a similar approach as with the Tutorial but use Oracle and the delivered schema Scott/Tiger tables (see sqlplus/demobld.sql) which includes the tables: EMP, DEPT, BONUS, SALGRADE, DUMMY.

This should illustrate:
– creating the connection defintion
– minimum manual code so that scaffold works
– related tables and keys working (EMP, DEPT, BONUS)
– full functional list, search, edit, delete
– minimum required files to get a legacy schema to work with Rails and scaffold

Yes it’s simple example but at least all of us dummies can use it to follow? The example should be complete with database connection information and files and where to put them (e.g. app/xxx, config/xxx, app/controller/xxx, etc.).

I’ve read and read and am still a bit (more like a lot) fuzzy on how to get RubyonRails/scaffold to work on an existing schema. The post shows snippits but I’m fuzzy on where to make the mods and how to get Rails to connect to the DB (yes I’ve modified database.yml but it doesn’t connect). I’ve done the Ruby → samples → DBD → oracle-0.2.11 → samples → test.rb

However, this isn’t Rails nor does it use scaffold. I’ve found lots of MySQL stuff but for me in my environment it’s got to be Oracle.

I’m looking at replacing a small PHP app with Rails. It should increase my productivity by 100 fold. I just can’t get Rails to work with Oracle yet.

Please help – this stuff looks FABULOUS! I can’t wait to contribute!!!!!

Perhaps helpful:

I couldn’t get scaffolding to pick up the column names but it did recognize the table and create a paginated view for the number of rows. Here’s how I use Oracle with Rails

database.yml


development:
  adapter: oci
  host: host.example.com/databasename  # include the db here
  username: user
  password: pass

etc.

item.rb – Model


class Item < ActiveRecord::Base

  # include the schema name in your rails table name attribute
  set_table_name 'mig31.cismaster'  # schema.table
  set_primary_key 'objectname'
  
  # map rails joins to the legacy table names and columns
  has_and_belongs_to_many :collections, :join_table=>"mig31.object2collection", :foreign_key=>'objectname', :association_foreign_key=>'collectionid'

end

items_controller.rb – Controller


class ItemsController < ApplicationController

  def index
    @pages, @items = paginate :items, :order_by=>"objectname"
  end

end

index.rhtml – View


...
<ul>
<% for item in @items %>
  <li><%= item.title %> has a unique id of <%= item.objectname %></li>
<% end %>
...

This helps but (and maybe I’ll end up doing it) I was looking for a full zip file to expand which has all the associated files to run rails (with scaffold) against Oracle and the demo user Scott/Tiger. This would go a long way to thrusting those of us that work exclusively on production Oracle apps.

Well, I’m almost there. I’ve got Rails listing updating and deleting the Scott/Tiger demo tables (EMP, DEPT, SALGRADE, BONUS). One problem I’m struggling with is that these tables don’t use sequences for their primary keys (EMPEMPNO is next larger value; DEPTDEPNO is user defined, BONUS has a composite primary key of EMPNO, JOB, SAL, COMM).

I’m trying many different things. One suggestion is to use the “before_validate_on_create” RAILS API. However, I can’t find anyone who’s actually done it. David you out there?

Once I get a decent code set I’ll post it for others to use.

There is an example with a newer demo schema (HR) on OTN
HR Schema on Rails