Skip to content

Instantly share code, notes, and snippets.

@Heliosmaster
Last active December 11, 2015 10:18
Show Gist options
  • Save Heliosmaster/4585374 to your computer and use it in GitHub Desktop.
Save Heliosmaster/4585374 to your computer and use it in GitHub Desktop.
class Something
include DataMapper::Resource
property :id, Serial
property :value, Float, :required => true
property :date, Date, :required => true, :unique => true
property :user, Integer
validates_within :value, :set => (0..200)
end
get '/' do
if logged_in?
@variable = Something.all(:user => current_user.id)
@title = "Home"
flash[:notice] = "Hi #{current_user.email}!"
else
@variable = Something.all
@title = "Home (not logged in)"
flash[:notice] = "Hi anonymous, why not log in?"
end
haml :home
end
get '/:id' do
@variable = Something.get params[:id]
@title = "Stuff ##{params[:id]}"
haml :show_stuff
end
== Sinatra/1.3.3 has taken the stage on 4567 for development with backup from Thin
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:4567, CTRL+C to stop
127.0.0.1 - - [21/Jan/2013 12:12:02] "GET / HTTP/1.1" 200 1025 0.0117
127.0.0.1 - - [21/Jan/2013 12:12:03] "GET /datepickr.css HTTP/1.1" 304 - 0.0093
127.0.0.1 - - [21/Jan/2013 12:12:03] "GET /datepickr.min.js HTTP/1.1" 304 - 0.0007
NoMethodError - undefined method `date' for nil:NilClass:
/home/davide/project/views/show_stuff.haml:2:in `evaluate_source'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/tilt-1.3.3/lib/tilt/template.rb:209:in `instance_eval'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/tilt-1.3.3/lib/tilt/template.rb:209:in `evaluate_source'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/tilt-1.3.3/lib/tilt/template.rb:144:in `cached_evaluate'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/tilt-1.3.3/lib/tilt/template.rb:127:in `evaluate'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/tilt-1.3.3/lib/tilt/haml.rb:24:in `evaluate'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/tilt-1.3.3/lib/tilt/template.rb:76:in `render'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:686:in `render'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:582:in `haml'
siliwe.rb:59:in `block in <main>'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:1265:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:1265:in `block in compile!'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `[]'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `block (3 levels) in route!'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:851:in `route_eval'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `block (2 levels) in route!'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:872:in `block in process_route'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:870:in `catch'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:870:in `process_route'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:834:in `block in route!'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:833:in `each'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:833:in `route!'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:936:in `dispatch!'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in `block in call!'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `block in invoke'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `catch'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `invoke'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in `call!'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:755:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.4/lib/rack/session/abstract/id.rb:210:in `context'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.4/lib/rack/session/abstract/id.rb:205:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/rack-protection-1.3.2/lib/rack/protection/xss_header.rb:27:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/rack-protection-1.3.2/lib/rack/protection/path_traversal.rb:16:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/rack-protection-1.3.2/lib/rack/protection/json_csrf.rb:17:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/rack-protection-1.3.2/lib/rack/protection/base.rb:48:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/rack-protection-1.3.2/lib/rack/protection/base.rb:48:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/rack-protection-1.3.2/lib/rack/protection/xss_header.rb:27:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.4/lib/rack/logger.rb:15:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.4/lib/rack/commonlogger.rb:33:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:136:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:129:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.4/lib/rack/head.rb:9:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.4/lib/rack/methodoverride.rb:21:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/showexceptions.rb:21:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:99:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in `block in call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:1471:in `synchronize'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/thin-1.5.0/lib/thin/connection.rb:81:in `block in pre_process'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/thin-1.5.0/lib/thin/connection.rb:79:in `catch'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/thin-1.5.0/lib/thin/connection.rb:79:in `pre_process'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/eventmachine-1.0.0/lib/eventmachine.rb:1037:in `call'
/home/davide/.rvm/gems/ruby-1.9.3-p194/gems/eventmachine-1.0.0/lib/eventmachine.rb:1037:in `block in spawn_threadpool'
%p
="The value for #{@variable.date.strftime('%d %b %Y')} is #{@variable.value}. Do you wish to"
%a{:href => "/#{params[:id]}/edit"} change
it?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment