-
-
Save paul/466095 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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