oookk, so i have 2 actions , create and destroy, i can get
session[:cart_id] from inside the create method but not from inside
the delete method.
def create
@cart = current_cart
Rails.logger.debug "SESSION INFO HERE
#{session[:cart_id]}" this here is 18
.
.
.
def destroy
# @cart = current_cart
@line_item = LineItem.find(params[:id])
Rails.logger.debug "SESSION INFO HERE
#{session[:cart_id]}" this here is nil
.
.
.
here is how i create the cart
private
def current_cart
begin
Cart.find(session[:cart_id])
rescue ActiveRecord::RecordNotFound
Rails.logger.debug "SESSION IS #{session.inspect}" <==
is empty when i call it from the destroy method
cart = Cart.create
session[:cart_id] = cart.id
cart
end
end
with AJAX, if your rails app is on a different domain than the page
hosting the form the cookies may get blocked resulting in no session
information being available.
Do a global search through your app and make sure you are not
accessing the session anywhere else.
If there are any other references but you believe that you are not
accessing them then put ruby-debug breakpoints at each and make sure
you do not get there.
When the create action gets called is there also another ajax action
that gets triggered by the browser at roughly the same time? There can
be race conditions when that sort of things happens.
in debuggin, if i stop to check the session during the destroy action i get this
“DEPRECATION WARNING: Disabling sessions for a single controller has been deprecated. Sessions are now lazy loaded. So if you don’t access them, consider them off. You can still modify the session cookie options with request.session_options. (called from block in at_line at (eval):5)”
my rails.js file i installed with jquery rails, is not properlly passing the csrf token so
“The request will also not include the required CSRF data, and as of Rails 3.0.4 the session is silently reset instead of throwing an ActionController::InvalidAuthenticityToken error. This is why you suspect the authentication issue lies with Devise, but it is actually being triggered within Rails itself.”
that is why i cant see the session from the destroy action, when i remove
protect_from_forgery
from the application_controller everything works ok , it also works if the request is not ajax based with protect_from_forgery enable.