Skip to content

Instantly share code, notes, and snippets.

@wallace
Created March 24, 2014 19:37
Show Gist options
  • Save wallace/9747462 to your computer and use it in GitHub Desktop.
Save wallace/9747462 to your computer and use it in GitHub Desktop.
class ExampleController < ApplicationController
def create
# something that calls private method
# ...
end
private
def private_method
params.
fetch(:top_level).
fetch(0).
fetch(:another_attribute)
rescue
# do something that let's us
# render text: "Invalid query parameters", status: :unprocessable_entity
# at the top level
end
end
@stevenharman
Copy link

Rails will issue a 422 : Unprocessable Entity from the respond_with handler if the object you give it is invalid. Does that help?

@wallace
Copy link
Author

wallace commented Mar 24, 2014

Not in this specific case.

@stevenharman
Copy link

I might have the private method return either the real object or a benign object which can then be used as normal. i.e., the private method is just a factory to map from the web (HTTP params) to your domain. Meh?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment