Rails 4 - Respond only to JSON and not HTML

前端 未结 10 1220
栀梦
栀梦 2020-12-08 02:59

I\'m trying to build an API in rails 4, and am having an issue where rails returns a 500 error instead of a 406 when using respond_to :json and trying to access

10条回答
  •  盖世英雄少女心
    2020-12-08 03:24

    I'm a bit late to this but regarding your comment to this answer:

    I want all responses to be JSON

    The easiest solution would be:

    respond_to do |format|
      format.all { render :json => @posts }
    end
    

提交回复
热议问题