1

When an HTTP request comes into the server (in this case I'm running rails s which defaults to webrick) the message looks something like:

Started POST "/cards" for 127.0.0.1 at 2011-11-05 15:04:29 -0400
  Processing by CardsController#create as JS

I'm wondering how to get the value JS in this case, or HTML. Sorry I can't be more explicit, I'm not sure what that value is called. Anyone have any ideas?

Thanks

cmwright
  • 3,406
  • 5
  • 26
  • 33

1 Answers1

2

You can use request.format to get the format. It'll return "text/javascript" for JS requests, "text/html" for HTML, "application/json" for JSON, etc.

Also, you would typically use this in a respond_to block:

respond_to do |format|
  format.html { do something }
  format.js { do something else }
end
Dylan Markow
  • 123,080
  • 26
  • 284
  • 201