I probably didn't understand STI or whatever inheritance of rails :)
I need to implement a design where I have a form; on upload I submit, but if the user is not logged in, she needs to login via openid (only access supported). Thus this implies a redirect, and the best thing I could come up with so far is to temporarily save the data, and on successful login actually create the real object. I wanted to have two separate tables for the objects; the Site object is the one to be created, the Sitetmp is the temporary store, and it has an additional field called nonce; (on successful login, the nonce will be compared, and if ok, the Sitetmp instance deleted and a new Site one created)
The DB:
#schema.rb
create_table "sites", force: true do |t|
t.string "name"
t.date "date"
t.text "description"
t.float "lat"
t.float "lon"
t.date "updated"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "sitetmps", force: true do |t|
t.string "nonce"
t.string "name"
t.date "date"
t.text "description"
end
The Subclass:
#app/models/sitetmp.rb
class Sitetmp < Site
attr_accessor :nonce
end
The Superclass:
#app/models/site.rb
class Site < ActiveRecord::Base
validates :name, uniqueness: true, :presence => true,
:length => { :minimum => 5 }
validates :date, :presence => true
has_many :images, :inverse_of => :site
end
It seemed to be all set, but when I actually want to access the temporary object on successful login, it tells me
SQLite3::SQLException: no such column: sites.nonce: SELECT "sites".* FROM "sites" WHERE "sites"."nonce" = '059253928646750523787961570357' LIMIT 1
The code in the controller causing this is:
if nonce
@tmp = Sitetmp.find_by nonce: nonce
Clearly I am trying to access the Sitetmp instance by its nonce attribute, but rails is resolving to actually access the Site class - which doesn't have a nonce attribute.
What am I doing wrong? How do I correctly find the Sitetmp object by nonce in order to create a valid Site object from it?