Sal Gonzalez
unread,Dec 30, 2011, 11:28:10 AM12/30/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Composite Keys for ActiveRecord
Hi all, I am trying to write (and learn) a rails application against
a legacy DB with CPKs, but I am having trouble out of the gate.
I am running rails 3.0.11, sqlite3, cpk 3.1.10 & a copy of
composite_migrations I pulled off the web, and I'm having a problem
getting started on this. I scoured the net to no avail on an in-depth
tutorial of this gem geared to a beginner rails programmer :(
Here is the extent of what I have done from a bare rails app:
* added a reference to cpk in the Gemfile
* created a very basic scaffold consisting only of 2 decimal fields
which are a CPK via:
`rails generate scaffold Claims ss:decimal claimnum:decimal`
* changed the migration to require composite_migrations and set the
create table line to:
'create_table :claims, :primary_key => [:ss, :claimnum] do |t|'
* changed the model to require cpk and include:
'set_primary_keys :ss, :claimnum'
* changed the controller to require cpk
* added a require for cpk into the dev environment .rb
* added 'match ':controller/:action/:id', :id => /\w+(,\W*\w+)*/' to
routes.rb directly below the resources line
After this I ran the migration (successfully), imported some data into
the sqlite table, ran the server and got a routing error when viewing
the index:
No route matches {:action=>"show", :id=>#<Claim ss: #<BigDecimal:
7f5a778c58b0,'0.99999999E8',9(18)>, claimnum: #<BigDecimal:
7f5a778c57c0,'0.99999998E7',9(18)>>, :controller=>"claims"}
I've tried to muck around with the route match statement, as well as
postfixing the columns with '_id' but I get the same routing error.
I'm sure this all boils down to my inexperience with rails in
general. Any help would be greatly appreciated.
P.S. I am creating the DB locally for testing, ideally I'd use the
existing legacy DB once I have a basic handle on rails and getting it
to behave with this gem.