How to send http-status using JBuilder Gem

http-status-codes, json, ruby-on-rails

Solution

This works:

controller

def some_action
  render status: :bad_request
end

some_action.jbuilder

json.something "test"

Problem

Am using Rails 3.0.19 and JBuilder Gem 2.0.6 to render JSON responses. JBuilder: https://github.com/rails/jbuilder Following is the code am using to send error-messages for a specific API. ``` render :json, :template=>"/api/shared/errors.json.jbuilder", :status=> :bad_request ``` For some reason, the client receives 200-ok status. While, I have expected 400 (bad_request). Any help, please? Here is my code in detail: ``` def render_json_error_messages #render :template=> "/api/shared/errors.json.jbuilder", :status=> :bad_request, :formats => [:json] respond_to do |format| format.json { render :template=> "/api/shared/errors.json.jbuilder", :status=> 400 } end end ``` And in a before_filter method, I use `render_json_error_messages`

Original source