Q: Rails respond to restful input via html We have a Rails app where we are adding Workorders via the Restful interface.
This is the controller code:
# POST /workorders
# POST /workorders.json
def create
  @workorder = Workorder.new(params[:workorder])

  respond_to do |format|
    if @workorder.save
      format.html { redirect_to @workorder, notice: 'Workorder was successfully created.' }
      format.json { render json: @workorder, status: :created, location: @workorder }
  else
      format.html { render action: "new" }
      format.json { render json: @workorder.errors, status: :unprocessable_entity }
    end
  end
end

When the workorder is added, the response is coming from this line of code:
format.html { redirect_to @workorder, notice: 'Workorder was successfully created.' }

What the other app gets in return is:
<html><body>You are being <a href="http://ndeavor.ameipro.com/workorders/50">redirected</a>.</body></html>

50 is the new workorder.id, but we are having trouble parsing that.
Is there a way to put the workorder.id into the header of what's returned?  We need the app thats sending the data to know what the new workorder.id is.
Also, is there a way to know that the request is coming from the other application instead of a new workorder created in the Rails ui.
Thanks for your help!!
UPDATE 1
Please clarify something about REST for me.  If the restful input is json, then the controller responds back with json?  If the input is html, can the controller respond with json or only html?
When I'm testing using RestClient, is there someway to turn this url into json input or add something that asks for a json response?
http://localhost:5000/types?type[id]=318&type[typecode]=test4 


A: response.headers['ETag'] = @workorder.id might work.
But a better way would be to send over json and have your client parse that, instead of trying to scrape data out of HTML.
Looking at the documentation for Mule, it looks like you should be able to set the accept header like this:
props.put("Accept", "application/json");

To which the rails app will respond with the format.json block.
Alternatively, you can just make it always respond with json by taking the render :json call out of the respond_to block:
def create
  @workorder = Workorder.new(params[:workorder])
  if @workorder.save
    render json: @workorder, status: :created, location: @workorder
  else
    render json: @workorder.errors, status: :unprocessable_entity
  end
end

