I am working on a website that (in nature) expects a client_id
to 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_id
was passed in. This also causes a problem with writing link_to
or redirect
because 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