Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Controller processing as */*

I have a js.erb file where I perform an ajax GET like so:

$.get("<%= j @stored_location %>");

All is well, however my server logs show this:

Processing by XyzController#index as */*

I know that "/" means "any format", and everything is working just fine, so I'm wondering if there's any point in trying to ensure that Rails processes this action explicitly as :js. Do I need to add something to the $.get call? Should I bother?

like image 230
stephenmurdoch Avatar asked Feb 17 '14 04:02

stephenmurdoch


1 Answers

1: Should you bother?

I think it is always a good habit to be as exact and explicit as you can with those kind of things. If you would like to be able to answer differently for the same URL depending on the request time in the future you will have to deal with this issue. So yes, you should bother. Worse case, you'll learn something new from this :)

2: How to fix this?

The Jquery Get documentation lists a dataType argument you can pass to your call. So, for example, if you are expecting a JSON to return from the server your request might look like this:

$.get({
  url: "<%= j @stored_location %>",
  data: data,
  success: success,
  dataType: "json"
});

Have a look at the documentation and decide what's best for you case.

like image 81
Erez Rabih Avatar answered Sep 20 '22 02:09

Erez Rabih