impressionist
impressionist copied to clipboard
Use impressionist within Grape::Endpoint
Hi
I'm using Grape to build an API. I'd like to use impressionist within the Grape endpoints, but I'm getting this error:
undefined method `impressionist' for #<Grape::Endpoint:0x007f9205f6bd70
I suppose it's related to use impressionist outside a controller. Is there any way to use it there?
Thank you in advance
+1 @sonxurxo have you figured out a solution for your problem?
Not yet, I didn't have time to dive on this. In the following days I'll be working on this, I'll post here my findings.
just use:
imp = Impression.new
imp.impressionable_type = object.class.to_s
imp.impressionable_id = object.id
imp.user_id = current_user.nil? ? 0 : current_user.id
imp.controller_name = "topics"
imp.action_name = "show"
imp.request_hash = Digest::SHA2.hexdigest(Time.now.to_f.to_s+rand(10000).to_s)
imp.ip_address = env['REMOTE_ADDR']
imp.session_hash = request.session_options[:id]
imp.referrer = request.referer
imp.save
And to update the counter cache use this:
slave = Impressionist::UpdateCounters.new(object)
slave.update
@nguyenchiencong Thank you, it's working for me.