Skip to content

Instantly share code, notes, and snippets.

@paul
Forked from pezra/gist:466086
Created July 6, 2010 23:41
Show Gist options
  • Save paul/466095 to your computer and use it in GitHub Desktop.
Save paul/466095 to your computer and use it in GitHub Desktop.
class MyResource
include Spinal::Resource
attribute :foo, String, :required => true
attribute :bar, Integer
render(:html).with(:template => 'my_resource')
render(:json).with(JsonRenderer)
def self.load(id)
m = MyModel.find(id)
merge!(m.attributes)
# or
foo = m.foo_bar
end
# Has to be a class method, because it's something that returns a new resource object; analagous to Model.find
def self.get(foo)
load!(foo)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment