I'm creating a table called Index
. Here's the migration:
class CreateIndices < ActiveRecord::Migration
def change
create_table :indices, {:id => false} do |t|
t.string :name
t.float :returns, array: true, default: []
t.float :navs, array: true, default: []
t.float :sharpe
t.timestamps
end
execute "ALTER TABLE indices ADD PRIMARY KEY (name);"
end
end
That all works fine. I saw in another Stack Overflow question that I have to include the set_primary_key
command in my model to get it to work, so I have the following in the index.rb
class Index < ActiveRecord::Base
set_primary_key :name
end
Besides these two files, I haven't changed anything from the default Rails scaffolding (the app was created with Postgres as the default database). When I go to localhost:3000/indices
, I get the following error
undefined method `set_primary_key' for #<Class:0x37132e0>
If I comment out the set_primary_key
line it loads the regular empty scaffold, but I assume this does not give me the primary key functionality that I want. What am I doing wrong?