updated at
データベース オブジェクトの属性を取得しようとしていますが、うまくいきません。他の属性は取得できますが、updated_at
またはcreated_at
属性は取得できません。id
また、属性も取得できないことに気付きました。私の中で宣言してPocket.new
いないものは存在しないようです。これが私のコードです:
ちなみにレールは使っていません。と を使用sinatra-activerecord
してsinatra
います。
モデル
class Pocket < ActiveRecord::Base
def retrieve(consumer_key)
url = "get/"
pocket_url = join_url(url)
# time = Time.now.to_i
token = self.token
puts consumer_key
puts self
puts time = self.updated_at #.to_i this is where it happens.
options = {
:access_token => token,
:consumer_key => consumer_key,
:since => (time if defined? time)
}
hello = RestClient.post pocket_url, options
# JSON.parse(hello)
end
コントローラ
get '/auth/pocket/callback' do
[…]
pocket = Pocket.new(token: @token, user: @user)
DB 移行
class CreatePocket < ActiveRecord::Migration
def up
create_table :pockets do |t|
t.string :user
t.string :token
t.timestamps
end
end
def down
drop_table :users
end
end