Big sinatra problems
- by Joel M.
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?