datamapper / dm-timestamps

DataMapper plugin for magical timestamps
http://datamapper.org/
MIT License
9 stars 13 forks source link

Trying to set updated_at in a callback crashes Sinatra #7

Open aledalgrande opened 12 years ago

aledalgrande commented 12 years ago

Hi, I didn't now about dm-timestamps, even if it was used by my app because I required the entire 'datamapper' gem.

In my datamapper resource class I had:

  before :save do
    self.updated_at = Time.now
  end

Then when I restarted thin I got:

TypeError at /
type mismatch: String given
/Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:812:in `match'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:812:in `process_route'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:777:in `block in filter!'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:777:in `each'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:777:in `filter!'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:885:in `dispatch!'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `block in call!'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `block in invoke'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `catch'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `invoke'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `call!'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:705:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-1.4.1/lib/rack/logger.rb:15:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-1.4.1/lib/rack/head.rb:9:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/showexceptions.rb:21:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `block in call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:1416:in `synchronize'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-1.4.1/lib/rack/lint.rb:48:in `_call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-1.4.1/lib/rack/lint.rb:36:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-1.4.1/lib/rack/showexceptions.rb:24:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/shotgun-0.9/lib/shotgun/loader.rb:86:in `proceed_as_child'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/shotgun-0.9/lib/shotgun/loader.rb:31:in `call!'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/shotgun-0.9/lib/shotgun/loader.rb:18:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/shotgun-0.9/lib/shotgun/favicon.rb:12:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/shotgun-0.9/lib/shotgun/static.rb:14:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-1.4.1/lib/rack/builder.rb:134:in `call'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/thin-1.3.1/lib/thin/connection.rb:80:in `block in pre_process'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/thin-1.3.1/lib/thin/connection.rb:78:in `catch'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/thin-1.3.1/lib/thin/connection.rb:78:in `pre_process'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/thin-1.3.1/lib/thin/connection.rb:53:in `process'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/thin-1.3.1/lib/thin/connection.rb:38:in `receive_data'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/thin-1.3.1/lib/thin/backends/base.rb:61:in `start'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/thin-1.3.1/lib/thin/server.rb:159:in `start'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:in `run'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/gems/shotgun-0.9/bin/shotgun:156:in `<top (required)>'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/bin/shotgun:19:in `load'
    /Users/ale/.rvm/gems/ruby-1.9.2-p290@status2012/bin/shotgun:19:in `<main>'

I'm sure I was not doing the right thing, but as the error is quite misleading, it took me a while to figure out what was wrong.

Thanks, Alessandro