Last active
December 21, 2015 19:29
-
-
Save svs/6354889 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module FoosController | |
class Index < ControllerAction | |
def get | |
@foos = Foo.all | |
succeed_with(FooPresenter.new(@foos).to(format)) # if you want more control over presentation, hand off to the presenter | |
end | |
end # Index | |
class Create < ControllerAction | |
def post | |
@foo = Foo.new(params) | |
@foo.save ? succeed_with(@foo.to_json) : fail_with(@foo.errors.to_json, 422) # ControllerAction provides #fail_with and #succeed_with | |
end | |
private | |
def params | |
# still mungeing params but now we only worry about stuff sent for the "create" action | |
super.except(:deleted_at) # ControllerAction gives us all the params. Here we do not allow :deleted_at, for example | |
# | |
end | |
end # Create | |
end #FoosController | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment