title: Set http status code 201 to an API response in action controller rails
body: <p>I'm new to rails and I'm building a Rails app that will function as an API. Currently I don't have any models or database just an <code>Api::ProductController</code> controller:</p>
  
  <pre><code>class Api::ProductController &lt; ApplicationController
  
    def create
      Rails.logger.info "product was created and the parameters are #{product_params[:name]}, #{product_params[:age]}"
    end
  
    private
  
    def product_params
      params.permit(:name, :age)
    end
  end
  
  </code></pre>
  
  <p>. As I continue and wrote the request Rspec:</p>
  
  <pre><code>
  RSpec.describe Api::productsController, type: :request do
  
    it "creates a product" do
      post "/api/products", params: { name: "name", age: "22"}
  
      expect(response).to have_http_status(:created)
      expect(response.body).to include("product was successfully created.")
    end
  end
  </code></pre>
  
  <p>But when I run the request rspec test on the command line I get the following error:</p>
  
  <pre><code>Failure/Error: expect(response).to have_http_status(:created)
         expected the response to have status code :created (201) but it was :no_content (204)
  
  </code></pre>
  
  <p>My question is how can I set the status code to :created (201)? is the Head method a good approach? any solution or guiding would be appreciated!</p>