impressionist
impressionist copied to clipboard
Nil value for session_hash
impressionist(@object, nil, unique: [:session_hash]) always gives NIL value for session_hash.
first time it inserts the record, later on every request it says Record Already Exist because it always find Nil value for session_hash. it looks it does not log the rails-4 session value into "session_hash"
Any help on this ? I'm using Rails 4.1.6, ruby 2.1.3p242 and impressionist (1.5.1)
+1
As per my little research, i see problem may be with def session_hash in ImpressionistController module. for rails-4 this needs to be fixed.
somehow impressionist is using request.session_options[:id] to get the session ID but in rails-4 it is giving a nil value.
Hence, impressionist with session_hash is not getting the correct SESSION ID and its failing.
For someone else who is also facing this issue. temporarily overriding session_hash did the job. once we will get the proper fix in impressionist, we will remove this function.
def session_hash request.session.id end
it seems to be working fine.
Hi @kashifnaseer I tried overriding the session_hash in my initializer like so
ImpressionistController::InstanceMethods.class_eval do
def session_hash
request.session.id
end
end
but I get <ActionDispatch::Request::Session:0x7fa2ce2e3650 not yet loaded>
when trying to access the session. Any ideas why it isn't loaded yet? Where/How did you override the method?
Thanks!
...and just like that I found a solution. It's due to lazy loading of the session. Putting a session[:init] = true
before accessing the session works. It now looks like this:
ImpressionistController::InstanceMethods.class_eval do
def session_hash
session[:init] = true
request.session.id
end
end
Hope that helps!
:+1:
@germs12 Where did you place that file and what did you name it? Thanks!
@kashifnaseer Any ideas? http://stackoverflow.com/questions/29149659/using-impressionist-in-rails-4-1-is-not-logging-views-by-session-hash
This is probably the cause of this bug. https://github.com/rails/rails/pull/19309/files