I need to restrict respond_to to JSON only, because I am constructing a web service that will provide JSON formatted output only. How do I do this?
I need to restrict respond_to to JSON only, because I am constructing a web
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could create a
before_filter, defined in theApplicationControllerwhich would check therequest.formatfor JSON and then respond with an appropriate 4xx HTTP error code and message if not matched.If to enforce this for all controllers the invoke the filter in the
ApplicationController, otherwise invoke it in the selected controllers of interest.