I have the following action, appointments_for_week:
class StylistsController < ApplicationController
def appointments_for_week
stylist = Stylist.find(params[:id])
date = Time.zone.parse(params[:date])
appointments = stylist.salon.appointments_flat(stylist.id,
(date + 1.day).beginning_of_week.advance(:days => -1),
(date + 1.day).end_of_week.advance(:days => -1) + 1.day)
respond_to do |format|
format.json { render :json => @appointments }
end
end
Something really weird is happening. If I log in and then simply browse to this action’s route, nothing happens. I get a blank page, which is what I would expect. If I then go to another page and refresh, I’m still logged in, which is of course what I would expect.
However, if I do a request on this action via ajax, it kicks me out. I find this incredibly strange. If I add a before_filter to skip authentication, I no longer get kicked out, but I of course don’t want to skip authentication. I don’t understand why this action can be accessed via a regular request but not an ajax request.
What could be happening here?
(I’m on Rails 3.2.1, in case it matters.)
Okay, I figured it out, two seconds after I spent forever putting together my question.
The ajax request was
POST. Switching toGETmade it work.Interestingly, it was
POSTbefore and the same exact JavaScript worked. The only thing I changed was that I updated my version of jQuery, so I guess it must have had something to do with it.