Can't you just put

respond_to :html, :json


at the top of your controller?

- Mike

On Mon, Feb 21, 2011 at 4:37 PM, Mark Mansour <[email protected]> wrote:

> In my API I want to reject non JSON calls so I have
>
> before_filter :reject_non_json_requests
>
>  def reject_non_json_requests
>
>     render :status => :unsupported_media_type,
>
>            :text => "" if request.content_type != 
> ActiveResource::Formats["json"].mime_type && params[:format] != "json")
>
>  end
>
>
> Is there a better way?
>
> On Mon, Feb 21, 2011 at 3:36 PM, Paul Annesley <[email protected]>wrote:
>
>> Rails respects the Accept header, but the :format URL parameter takes
>> precedence.
>> Best of both worlds.
>>
>>
>>
>> On Mon, Feb 21, 2011 at 1:14 PM, Korny Sietsma <[email protected]> wrote:
>> > does it? Sorry, haven't done any rails for a long time - I thought t was
>> the
>> > other way round.
>> > - K
>> >
>> > On Mon, Feb 21, 2011 at 1:11 PM, Mike Bailey <[email protected]>
>> wrote:
>> >>
>> >> On Mon, Feb 21, 2011 at 12:52 PM, Korny Sietsma <[email protected]>
>> wrote:
>> >>>
>> >>> One trick I've seen is people serving up application/json if the
>> Accept
>> >>> header includes it, but otherwise, providing a html wrapper that
>> >>> pretty-formats the json.  Can't remember where I've seen that, but it
>> seemed
>> >>> a clever way to make a json UI a bit more user-friendly for dumb
>> users.
>> >>
>> >> JSON is no place for 'dumb users'.
>> >>>
>> >>> Incidentally, what are people's thoughts on serving json based on the
>> URL
>> >>> (i.e. ending in ".json") vs based on the Accept header (i.e. the Rails
>> way)?
>> >>
>> >> I think accepting both is the most flexible.
>> >> Rails supports '.json'. Did you mean the other way
>> >> round? http://www.goodfordogs.org/latest/2.json
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >> "Ruby or Rails Oceania" group.
>> >> To post to this group, send email to [email protected].
>> >> To unsubscribe from this group, send email to
>> >> [email protected].
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/rails-oceania?hl=en.
>> >
>> >
>> >
>> > --
>> > Kornelis Sietsma  korny at my surname dot com http://korny.info
>> > "Every jumbled pile of person has a thinking part
>> > that wonders what the part that isn't thinking
>> > isn't thinking of"
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Ruby or Rails Oceania" group.
>> > To post to this group, send email to [email protected].
>> > To unsubscribe from this group, send email to
>> > [email protected].
>> > For more options, visit this group at
>> > http://groups.google.com/group/rails-oceania?hl=en.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ruby or Rails Oceania" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/rails-oceania?hl=en.
>>
>>
>
>
> --
> Mark Mansour
> +61(4) 0535 0175
> http://agilebench.com/
> Follow Us on Twitter @agilebench
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Ruby or Rails Oceania" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rails-oceania?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to