Created
March 24, 2014 19:37
-
-
Save wallace/9747462 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 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 |
Not in this specific case.
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
Rails will issue a
422 : Unprocessable Entity
from therespond_with
handler if the object you give it is invalid. Does that help?