0

I am working on a website that (in nature) expects a client_idto be passed to the application to turn on/off branding (depending on the client_id).

Here is my ApplicationController

  helper_method :current_client
  before_filter :set_client

   def set_client
     unless params[:client_id].blank?
       session[:client_id] = params[:client_id] unless session[:client_id] == params[:client_id]
     else
       session[:client_id] = "default_client_id_goes_here"
     end
   end

  def current_client
    @current_client ||= Client.find_by_app_id(session[:client_id])
  end

Here is my problem:
If I send an AJAX request that depends on the current sessioned client, it always defaults down to assuming no client_idwas passed in. This also causes a problem with writing link_toor redirectbecause you have to keep up with the client_id param throughout the entire app. Is there anyway to continue access to the session variables even with an ajax call?

CSRF Ajax Setup:

$.ajaxSetup
    beforeSend: (xhr) ->
        sid = $("meta[name='csrf-token']").attr "content";
        xhr.setRequestHeader "X-CSRF-Token", sid
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189
  • Are you sending the CSRF token? (E.g., http://stackoverflow.com/questions/5126721/rails-not-reloading-session-on-ajax-post, http://stackoverflow.com/questions/5241213/rails-session-is-blank-when-using-http-put, etc. etc. etc.) – Dave Newton Aug 08 '12 at 17:50
  • Yes, updated my question with my CSRF Ajax Setup – dennismonsewicz Aug 08 '12 at 17:52

0 Answers0