Big sinatra problems
Posted
by Joel M.
on Stack Overflow
See other posts from Stack Overflow
or by Joel M.
Published on 2010-03-31T19:08:21Z
Indexed on
2010/04/01
23:13 UTC
Read the original article
Hit count: 453
Hi,
So I'm having huge trouble with sinatra.
Here's what I have:
require 'dm-core'
DataMapper.setup(:default, ENV['DATABASE_URL'] || 'sqlite3://my.db')
class Something
include DataMapper::Resource
property :id, Serial
property :thing, Text
property :run_in, Integer
property :added_at, DateTime
property :to, String
def schedule
cronify(self.thing+" to "+self.to, "http://url"+self.id.to_s, self.run_in)
end
def notify
text(self.thing, self.to)
end
end
Something.auto_upgrade!
The cronify method works. I tested it in irb. Also, the schedule instance method works, I tested it in the console.
However, it doesn't work in the route, even though it works in the console.
post '/add' do
@something = Something.create(blah) #this works fine
@something.schedule #this works fine in the console; not in the route.
end
I've tried everything, from @something.create(blah).schedule
(which also works fine in the console, but not in the route), to defining the method cronify
inside the sinatra helpers, and even calling cronify
directly on the route. Nothing works on the route.
What am I doing wrong?
© Stack Overflow or respective owner