Skip to content

Instantly share code, notes, and snippets.

@yb66
Forked from Heliosmaster/app.rb
Created January 21, 2013 12:40
Show Gist options
  • Save yb66/4585772 to your computer and use it in GitHub Desktop.
Save yb66/4585772 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'haml'
class Something
def self.all( h= {} )
[]
end
def self.get( id=1 )
obj = Object.new
class << obj
def date
Time.now
end
def value
"something"
end
end
obj
end
end
configure do
enable :inline_templates
end
helpers do
def logged_in?
false
end
end
get '/' do
if logged_in?
@variable = Something.all(:user => current_user.id)
@title = "Home"
else
@variable = Something.all
@title = "Home (not logged in)"
end
haml :home
end
get '/:id' do |id|
@variable = Something.get id
@title = "Stuff ##{params[:id]}"
haml :show_stuff
end
__END__
@@layout
%html
%head
%title= @title
%body
= "@variable = #{@variable.inspect}"
= yield
@@home
%h1
Home
@@show_stuff
%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