Skip to content

Instantly share code, notes, and snippets.

@svs
Last active December 21, 2015 19:29
Show Gist options
  • Save svs/6354889 to your computer and use it in GitHub Desktop.
Save svs/6354889 to your computer and use it in GitHub Desktop.
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