所以我试图获取updated at
我的数据库对象的属性,但它不起作用。我可以获得其他属性,但不能获得updated_at
orcreated_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)
数据库迁移
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