How to print in rails after a create api is called from an android

Viewed 173

I have an android app and a rails app. When a order is made from android, it calls create order API in rails app. So whenever a create order is successful in rails app,i want to perform a print action that prints the order bill using the data send from the android.

But the controller i created only gives a response either in json or html format. i.e

class API::V1::OrdersController << Api::ApiController
  def create
    @order = Order.create(
                    item: params[:item],
                    quantity: params[:quantity],
                    price: params[:price]
                    )
    if @order.persisted?
      respond_to do |format|
        format.json { notice: 'Order successfully created.' }
        format.html { render :print }
      end
    end
  end
end

This will only give back the response of 'Order successfully created.' when json is used or the html format page written in 'print.html.slim' to the android. But i want to print a order bill page from 'print.html.slim' when a order is persisted.

print.html.slim

table.table
  thead
    th Item Name
    th Quantity
    th Price
  tbody
    tr
      td = @order.item
      td = @order.quantity
      td = @order.price

Is there any way i can do this ?

1 Answers

What you have and what you seek are two different things.

Since you have set up your Rails server as an API end point, you can only return JSON values. For what you need, you should accept the JSON data in your android app and do what you wish with the data in your app (like displaying the confirmed order)

Related