charlotte-ruby / impressionist Goto Github PK
View Code? Open in Web Editor NEWRails Plugin that tracks impressions and page views
License: MIT License
Rails Plugin that tracks impressions and page views
License: MIT License
Looks like we blow up trying retrieved cached items when viewing a duplicated impressionist object.
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/impressionist-8f2c219b97d0/lib/impressionist/models/mongoid/impressionist/impressionable.rb:45:in update_impressionist_counter_cache' activesupport (3.2.11) lib/active_support/core_ext/object/try.rb:36:in
try'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/impressionist-8f2c219b97d0/lib/impressionist/models/mongoid/impression.rb:27:in block in <class:Impression>' activesupport (3.2.11) lib/active_support/callbacks.rb:416:in
_run__327048654__create__148435328__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in __run_callback' activesupport (3.2.11) lib/active_support/callbacks.rb:385:in
_run_create_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in run_callbacks' mongoid (2.4.3) lib/mongoid/callbacks.rb:43:in
block in run_callbacks'
mongoid (2.4.3) lib/mongoid/callbacks.rb:68:in call' mongoid (2.4.3) lib/mongoid/callbacks.rb:68:in
run_cascading_callbacks'
mongoid (2.4.3) lib/mongoid/callbacks.rb:42:in run_callbacks' mongoid (2.4.3) lib/mongoid/persistence/insertion.rb:25:in
block (2 levels) in prepare'
activesupport (3.2.11) lib/active_support/callbacks.rb:414:in _run__327048654__save__148435328__callbacks' activesupport (3.2.11) lib/active_support/callbacks.rb:405:in
__run_callback'
activesupport (3.2.11) lib/active_support/callbacks.rb:385:in _run_save_callbacks' activesupport (3.2.11) lib/active_support/callbacks.rb:81:in
run_callbacks'
mongoid (2.4.3) lib/mongoid/callbacks.rb:43:in block in run_callbacks' mongoid (2.4.3) lib/mongoid/callbacks.rb:68:in
call'
mongoid (2.4.3) lib/mongoid/callbacks.rb:68:in run_cascading_callbacks' mongoid (2.4.3) lib/mongoid/callbacks.rb:42:in
run_callbacks'
mongoid (2.4.3) lib/mongoid/persistence/insertion.rb:24:in block in prepare' mongoid (2.4.3) lib/mongoid/persistence/insertion.rb:22:in
tap'
mongoid (2.4.3) lib/mongoid/persistence/insertion.rb:22:in prepare' mongoid (2.4.3) lib/mongoid/persistence/operations/insert.rb:26:in
persist'
mongoid (2.4.3) lib/mongoid/persistence.rb:49:in insert' mongoid (2.4.3) lib/mongoid/persistence.rb:154:in
upsert'
mongoid (2.4.3) lib/mongoid/persistence.rb:177:in block (2 levels) in create' mongoid (2.4.3) lib/mongoid/persistence.rb:177:in
tap'
mongoid (2.4.3) lib/mongoid/persistence.rb:177:in block in create' mongoid (2.4.3) lib/mongoid/threaded/lifecycle.rb:173:in
_creating'
mongoid (2.4.3) lib/mongoid/persistence.rb:176:in create' C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/impressionist-8f2c219b97d0/app/controllers/impressionist_controller.rb:36:in
impressionist_subapp_filter'
C:/Ruby192/lib/ruby/gems/1.9.1/bundler/gems/impressionist-8f2c219b97d0/app/controllers/impressionist_controller.rb:6:in block in impressionist' activesupport (3.2.11) lib/active_support/callbacks.rb:539:in
_run__711426409__process_action__1032293139__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in __run_callback' activesupport (3.2.11) lib/active_support/callbacks.rb:385:in
_run_process_action_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (3.2.11) lib/abstract_controller/callbacks.rb:17:in
process_action'
actionpack (3.2.11) lib/action_controller/metal/rescue.rb:29:in process_action' actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:30:in
block in process_action'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in block in instrument' activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in
instrument'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in instrument' actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:29:in
process_action'
actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:207:in process_action' newrelic_rpm (3.5.8.72) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:34:in
block in process_action'
newrelic_rpm (3.5.8.72) lib/new_relic/agent/instrumentation/controller_instrumentation.rb:268:in block in perform_action_with_newrelic_trace' newrelic_rpm (3.5.8.72) lib/new_relic/agent/method_tracer.rb:240:in
trace_execution_scoped'
newrelic_rpm (3.5.8.72) lib/new_relic/agent/instrumentation/controller_instrumentation.rb:263:in perform_action_with_newrelic_trace' newrelic_rpm (3.5.8.72) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:33:in
process_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:121:in process' actionpack (3.2.11) lib/abstract_controller/rendering.rb:45:in
process'
actionpack (3.2.11) lib/action_controller/metal.rb:203:in dispatch' actionpack (3.2.11) lib/action_controller/metal/rack_delegation.rb:14:in
dispatch'
actionpack (3.2.11) lib/action_controller/metal.rb:246:in block in action' actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in
call'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in dispatch' actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:36:in
call'
journey (1.0.4) lib/journey/router.rb:68:in block in call' journey (1.0.4) lib/journey/router.rb:56:in
each'
journey (1.0.4) lib/journey/router.rb:56:in call' actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:601:in
call'
omniauth (1.1.3) lib/omniauth/strategy.rb:177:in call!' omniauth (1.1.3) lib/omniauth/strategy.rb:157:in
call'
omniauth (1.1.3) lib/omniauth/strategy.rb:177:in call!' omniauth (1.1.3) lib/omniauth/strategy.rb:157:in
call'
omniauth (1.1.3) lib/omniauth/strategy.rb:177:in call!' omniauth (1.1.3) lib/omniauth/strategy.rb:157:in
call'
omniauth (1.1.3) lib/omniauth/strategy.rb:177:in call!' omniauth (1.1.3) lib/omniauth/strategy.rb:157:in
call'
omniauth (1.1.3) lib/omniauth/strategy.rb:177:in call!' omniauth (1.1.3) lib/omniauth/strategy.rb:157:in
call'
omniauth (1.1.3) lib/omniauth/builder.rb:48:in call' mongoid (2.4.3) lib/rack/mongoid/middleware/identity_map.rb:33:in
block in call'
mongoid (2.4.3) lib/mongoid.rb:132:in unit_of_work' mongoid (2.4.3) lib/rack/mongoid/middleware/identity_map.rb:33:in
call'
newrelic_rpm (3.5.8.72) lib/new_relic/rack/error_collector.rb:8:in call' newrelic_rpm (3.5.8.72) lib/new_relic/rack/agent_hooks.rb:14:in
call'
newrelic_rpm (3.5.8.72) lib/new_relic/rack/browser_monitoring.rb:12:in call' actionpack (3.2.11) lib/action_dispatch/middleware/best_standards_support.rb:17:in
call'
rack (1.4.5) lib/rack/etag.rb:23:in call' rack (1.4.5) lib/rack/conditionalget.rb:25:in
call'
actionpack (3.2.11) lib/action_dispatch/middleware/head.rb:14:in call' actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:21:in
call'
actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:242:in call' rack (1.4.5) lib/rack/session/abstract/id.rb:210:in
context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in call' actionpack (3.2.11) lib/action_dispatch/middleware/cookies.rb:341:in
call'
actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:28:in block in call' activesupport (3.2.11) lib/active_support/callbacks.rb:405:in
_run__464494528__call__148435328__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in __run_callback' activesupport (3.2.11) lib/active_support/callbacks.rb:385:in
_run_call_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:27:in
call'
actionpack (3.2.11) lib/action_dispatch/middleware/reloader.rb:65:in call' actionpack (3.2.11) lib/action_dispatch/middleware/remote_ip.rb:31:in
call'
actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:16:in call' actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in
call'
railties (3.2.11) lib/rails/rack/logger.rb:32:in call_app' railties (3.2.11) lib/rails/rack/logger.rb:16:in
block in call'
activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in tagged' railties (3.2.11) lib/rails/rack/logger.rb:16:in
call'
actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in call' rack (1.4.5) lib/rack/methodoverride.rb:21:in
call'
rack (1.4.5) lib/rack/runtime.rb:17:in call' activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in
call'
rack (1.4.5) lib/rack/lock.rb:15:in call' actionpack (3.2.11) lib/action_dispatch/middleware/static.rb:62:in
call'
railties (3.2.11) lib/rails/engine.rb:479:in call' railties (3.2.11) lib/rails/application.rb:223:in
call'
railties (3.2.11) lib/rails/railtie/configurable.rb:30:in method_missing' rack (1.4.5) lib/rack/deflater.rb:13:in
call'
rack (1.4.5) lib/rack/content_length.rb:14:in call' railties (3.2.11) lib/rails/rack/log_tailer.rb:17:in
call'
thin (1.5.0) lib/thin/connection.rb:81:in block in pre_process' thin (1.5.0) lib/thin/connection.rb:79:in
catch'
thin (1.5.0) lib/thin/connection.rb:79:in pre_process' thin (1.5.0) lib/thin/connection.rb:54:in
process'
thin (1.5.0) lib/thin/connection.rb:39:in receive_data' eventmachine-1.0.1-x86 (mingw32) lib/eventmachine.rb:187:in
run_machine'
eventmachine-1.0.1-x86 (mingw32) lib/eventmachine.rb:187:in run' thin (1.5.0) lib/thin/backends/base.rb:63:in
start'
thin (1.5.0) lib/thin/server.rb:159:in start' rack (1.4.5) lib/rack/handler/thin.rb:13:in
run'
rack (1.4.5) lib/rack/server.rb:268:in start' railties (3.2.11) lib/rails/commands/server.rb:70:in
start'
railties (3.2.11) lib/rails/commands.rb:55:in block in <top (required)>' railties (3.2.11) lib/rails/commands.rb:50:in
tap'
railties (3.2.11) lib/rails/commands.rb:50:in <top (required)>' script/rails:6:in
require'
script/rails:6:in `
Is there capabilities to do this: @widget.impressionist_count(:filter => :action_name("show"))
I may be missing something, but it seems like the latest updates where loading has been moved to the ORM has resulted in all of the important impressionist methods not being added to the model. None of the methods are attached to the model and trying to run on the latest version gives a '[Model] is not impressionable!' error for everything.
def impressionist(obj,message=nil,opts={})
unless bypass
if obj.respond_to?("impressionable?")
if unique_instance?(obj, opts[:unique])
obj.impressions.create(associative_create_statement({:message => message}))
end
else
# we could create an impression anyway. for classes, too. why not?
raise "#{obj.class.to_s} is not impressionable!"
end
end
end
the highlighted code throws the exception.
I have used this in the model
is_impressionable :counter_cache => true
I'm using the sessions model outlined in the Ruby on Rails Tutorial. Unfortunately, Impressionist breaks this model when I call it like so:
def show
@user = User.find(params[:id])
impressionist(@user)
end
If I view a user profile (thus calling impressionist), I get logged out as soon as I click the next link or press refresh. Any idea what might be causing this?
Hi !
I'm getting this error using impressionist
in my Rails3.1 application, using mysql. I have a Service model which is_impressionable
and a impressionist :actions => [:show]
in my ServicesController
. The error appears only when I add the impressionist line to the controller.
The error is not very descriptive, just a
NoMethodError in ServicesController#show
undefined method `gsub!' for #<Arel::InsertManager:0x0000012a7ac170>
Any ideas will be appreciated!
tried to cache the impressions count here, but didn't work, it stills search for all the impressions in the database
I've added impressions_count (integer) column to all models, and added :counter_cache => true to all models that use is_impressionable, but it still searching for impressions in impressions table
Is it possible to only update the counter_cache field in my model and not write a new record in the impressionist table? even with Unique set to true, the impressionist table in the database could be ginormous!
I ran into a RecordNotFound exception as detailed in this SO: http://stackoverflow.com/questions/12148785/rails-find-by-id-raises-exception/12148939#12148939
Essentially if passed a bogus ID impressionist tries to log an impression for an object that doesn't exist. This might just be a problem with my setup, but here's my model setup:
is_impressionable :counter_cache => { :column_name => :views}
Deleting this line from my model allowed my controller action to properly handle the bogus id.
Hi,
I'm currently using latest version of impressionist in my project to register views and I'm also using it to save user-agent data from users.
In one of my controller, I use the following method:
impressionist(@tracker, request.env['HTTP_USER_AGENT'])
Impressionist saves the User Agent info into message variable.
Two example of the user agent info saved in the variables are:
The issue with it is that it's hard to parse such information. There are thousand of user agent info and it would be great if there's a way to categorize them automatically by Impressionist.
This would make Impressionist much more powerful ruby gem and eventually, it would also parse the IP address by country.
Is there a way to capture just unique views and not every view? I'm worried about all the excess records in my database since I don't need every impression counted. If we could do something like is_impressionable, :unique_only => true
in our model it would be awesome.
Regards,
Jordan
You should update the migrations to change the following columns to text rather than string:
request_hash, session_hash, message, referrer
This is actually a really big problem. Specifically the referrer
column. When searching from Google, the http referrer is very often over 255 characters which means any page using this gem will throw 500 errors when people try to visit from Google. That's no good. Especially because there's really no way to anticipate the problem until the code is in production.
I don't mind making a pull request, but it's an obvious fix, and I'm not sure how you want to do it (i.e. a new migration or amending the existing one). That said, if a pull request would be helpful, let me know and I'll take care of it.
attr_accessible is going to be enforced by default in the upcoming version of rails. Right now this gem doesn't work if attr_accesible is nil on the model because of mass assignment being used to create the impression records.
I think the methods that create impressions should use :without_protection => true
or some other method that gets around mass assignment to properly account for this.
Hello is this gem compatible with Mongoid?
I have try install this gem with mongoid but not works for me :(
Thank you!
It would be useful to be able to specify conditions for the counter cache, so that we could create multiple counter caches, say one for views, one for downloads, one for endorsements, etc.
Example:
is_impressionable :counter_cache => {:unique => true, :conditions => {:action_name => "download"}}
I saw in the other issue (#22) from a couple of months ago where this was working on rails 3.1.2. I have the same setup other than I have Rails 3.1.3, however it doesn't seem to be working for me - impressionist records the id just fine if I go to
.../article/13
but not
..article/title-of-article
I'm using Rails 3.1.3, Friendly_id 4.0.0-beta14 and impressionist 1.0.1
I'm wondering if you have any pointers for me on where to start looking and yes I have restarted the server :)
Eg. in a background job etc?
I would like to decouple it from model/controller.
I'm getting the following error when I try to call the impressionist count on a model that is_impressionable:
undefined method `impressionist_count' for #ActiveRecord::Relation:0x10489ac10
In my controller I'm called Model.impressionist_count
The impressions are successfully being stored in the impressions table, I just can't view them.
Rails 3.0.7 on Ruby 1.8.7
Deleting is_impressionable model objects is leaving orphaned records in the Impressions table
I'm continuing to have the problem first depicted in Issue # 7.
I've created a column in my impressionable table named impressions_count
and declared my model is_impressionable :counter_cache => true
. However, this still results in a undefined method `impressions_count=' error.
I think the key difference is that I'm using Rails 3.1. Have you encountered any issues with this? I'm happy to dig into it for a possible pull, but I wanted to make sure it wasn't something that was already on your radar.
impressionist(@widget,message:"wtf is a widget?") #message is optional
should be:
impressionist(@widget, :message => "wtf is a widget?") #message is optional
I added option in controller show method like impressionist(@post, :unique => [:session_hash])
but impressionist save all fields in mongodb. How to save only session_hash?
Maybe it was just my inexperience, but it might be beneficial to see something in the documentation for how to retrieve records on a model that belongs to another through a has_many association.
I have put this together to help.
Using the latest version of impressionist gem 'impressionist', '~> 1.2.0'
, it will not work with sitemap_notifier
version 1.0.0
. The error received is
.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.11/lib/active_record/dynamic_matchers.rb:55:in method_missing': undefined local variable or method
is_impressionable' for #Class:0x007f8902c8e690 (NameError)
I would like to cache both, total views and unique views.
The following does not make that happen (for obvious reasons):
is_impressionable :counter_cache => { :column_name => :view_counter_cache }
is_impressionable :counter_cache => { :column_name => :view_counter_cache_unique, :unique => true }
Is there a way to achieve this regardless, or could it be added?
Example:
is_impressionable :counter_cache => [{:column_name => :counter_cache}, {:column_name => :counter_cache_unique, :unique => true}]
or:
is_impressionable :counter_cache => {:counter_cache => {}, :counter_cache_unique => {:unique => true}}
According to the documentation on the main page, the table migration generated should look like
t.string "impressionable_type"
t.integer "impressionable_id"
t.integer "user_id"
t.string "controller_name"
t.string "action_name"
t.string "view_name"nested partials)
t.string "request_hash"
t.string "session_hash"
t.string "ip_address"
t.string "referrer"
t.string "message"
t.datetime "created_at"
t.datetime "updated_at"
However, running rails g impressionist
produces
t.string :impressionable_type
t.integer :impressionable_id
t.integer :user_id
t.string :controller_name
t.string :action_name
t.string :view_name
t.string :request_hash
t.string :ip_address
t.string :session_hash
t.text :message
t.text :referrer
t.timestamps
Looking at the source it looks like a simple issue with the generator, however it is causing problems. With the migration as this, I am receiving the following error
Mysql2::Error: BLOB/TEXT column 'message' used in key specification without a key length: CREATE INDEX `impressionable_type_message_index` ON `impressions` (`impressionable_type`, `message`, `impressionable_id`)
According to bundle
I'm using version 1.2.0
This issue is caused by upgrading from a version prior to 0.4.0. A new column was added for the referrer. Here is how you fix it:
Create a new migration in your rails app
rails generate migration version_0_4_0
Replace the code in the generated migration with this code: https://github.com/charlotte-ruby/impressionist/blob/master/upgrade_migrations/version_0_4_0.rb
Migrate your database
rake db:migrate
What do you think about adding some methods that let you easily "travel the users path" with something like imp.next
and imp.previous
?
Could be useful to analyze user behavior etc.
I think I could provide a PR given you like the idea.
uninitialized constant
... yadda yadda...
# /home/aaron/.rvm/gems/ruby-1.9.3-p392@mhmr/gems/impressionist-1.3.0/lib/impressionist/models/active_record/impression.rb:14:in `update_impressions_counter_cache'
1.2 works fine, i suspect that this was caused by df84891
In the README, you mention:
t.datetime "created_at" # I am not sure what this is.... Any clue?
t.datetime "updated_at" # never seen this one before either.... Your guess is as good as mine??
which is caused by the call to t.timestamps
in the migration template.
Thought you would want to know!
I'm having an issue with URLs that uses strings as their ID, like:
blabla.com/users/dude
Looking at this line, I found that it stores params[:id] directly inside impressionable_id column which results in my case storing NULL inside the table since impressionable_id column is supposed to be integer. One way to solve this is change the column type to string.
I tried something like:
impressionist(@user) #show action
but it didn't store the controller and the action names.
I'm using friendly_id gem that converts http://localhost:3000/posts/1 to http://localhost:3000/posts/titile-of-the-post .
I added impressionist to the controller and I also added is_impressionable to the model.
When I try to run @post.impression_count, the app doesn't show impressions.
Running from Rails C, I figured out that the class Impression was not registering impressionable_id: nil.
As you can see here:
irb(main):008:0> Impression.all
Impression Load (0.7ms) SELECT impressions
.* FROM impressions
=> [#<Impression id: 1, impressionable_type: "Post", impressionable_id: nil, user_id: nil, controller_name: "posts", action_name: "index", view_name: nil, request_hash: "82cb89bf5d40fc59a9358fe7cfa29ab9cee227f38ea9f10607a...", ip_address: "127.0.0.1", session_hash: "c1a3dd4fd1b4d2f725a230448027d2bf", message: nil, referrer: nil, created_at: "2011-12-25 22:02:25", updated_at: "2011-12-25 22:02:25">, #<Impression id: 2, impressionable_type: "Post", impressionable_id: 0, user_id: nil, controller_name: "posts", action_name: "show", view_name: nil, request_hash: "d6e0c423c5e4e7b361fd124cff5a6ee160d8509cc72768cee23...", ip_address: "127.0.0.1", session_hash: "c1a3dd4fd1b4d2f725a230448027d2bf", message: nil, referrer: "http://localhost:3000/", created_at: "2011-12-25 22:02:28", updated_at: "2011-12-25 22:02:28">, #<Impression id: 3, impressionable_type: "Post", impressionable_id: 0, user_id: nil, controller_name: "posts", action_name: "show", view_name: nil, request_hash: "b6749596053caf0257ef95a5fe41257ddc3672989c2144bef6b...", ip_address: "127.0.0.1", session_hash: "c1a3dd4fd1b4d2f725a230448027d2bf", message: nil, referrer: "http://localhost:3000/", created_at: "2011-12-25 22:04:03", updated_at: "2011-12-25 22:04:03">, #<Impression id: 4, impressionable_type: "Post", impressionable_id: 0, user_id: nil, controller_name: "posts", action_name: "show", view_name: nil, request_hash: "c505f1790072876b5cd0fa9db0030352dda5635cda94b262286...", ip_address: "127.0.0.1", session_hash: "c1a3dd4fd1b4d2f725a230448027d2bf", message: nil, referrer: "http://localhost:3000/", created_at: "2011-12-25 22:04:07", updated_at: "2011-12-25 22:04:07">, #<Impression id: 5, impressionable_type: "Post", impressionable_id: 0, user_id: nil, controller_name: "posts", action_name: "show", view_name: nil, request_hash: "2c3a245191a1c7399c33c98215ff4e31907fcbb0071d482df6c...", ip_address: "127.0.0.1", session_hash: "c1a3dd4fd1b4d2f725a230448027d2bf", message: nil, referrer: "http://localhost:3000/", created_at: "2011-12-25 22:07:52", updated_at: "2011-12-25 22:07:52">, #<Impression id: 6, impressionable_type: "Post", impressionable_id: 0, user_id: nil, controller_name: "posts", action_name: "show", view_name: nil, request_hash: "0a2831ccf5877b2ef70896e902b9891dc7354e00dbb9def2298...", ip_address: "127.0.0.1", session_hash: "c1a3dd4fd1b4d2f725a230448027d2bf", message: nil, referrer: "http://localhost:3000/", created_at: "2011-12-25 22:08:47", updated_at: "2011-12-25 22:08:47">]
irb(main):009:0>
I have issues with Friendly_ID that changes the way Rails 3.1 works, so all the helpers instead of request id from the instance model, it requests whatever slug from that object. I guess friendly_id is sending a string instead of the an id, but I don't know where to change that specific behavior.
When using the impressionist method directly:
impressionist(impressionable, "some message", :unique => [:session_hash])
Can I pass something like
impressionist(impressionable, :unique => [:session_hash])
I don't want to pass any message.
Thank you.
Is there any way of getting the impressionist_count
method to return only the count for a specific action?
If it's there, I could not find it. The information is in the database already, though, which would make it a nice and easy addition in my opinion: it's only an issue of deciding for a method signature.
A possibility could be
impressionist_count(:where => { :action_name => 'show' })
This should fit in nicely with the syntax for ActiveRecord's where
.
The model uses Single Table Inheritance. If the type column is blank, the issue does not occur.
In model:
is_impressionable :counter_cache => { :column_name => :view_counter_cache }
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
Backtrace:
impressionist (1.0.1) app/models/impressionist/impressionable.rb:47:in update_counter_cache' activesupport (3.1.3) lib/active_support/core_ext/object/try.rb:32:in
try'
impressionist (1.0.1) app/models/impression.rb:13:in update_impressions_counter_cache' activesupport (3.1.3) lib/active_support/callbacks.rb:401:in
_run_save_callbacks'
activesupport (3.1.3) lib/active_support/callbacks.rb:81:in run_callbacks' activerecord (3.1.3) lib/active_record/callbacks.rb:264:in
create_or_update'
activerecord (3.1.3) lib/active_record/persistence.rb:37:in save' activerecord (3.1.3) lib/active_record/validations.rb:50:in
save'
activerecord (3.1.3) lib/active_record/attribute_methods/dirty.rb:22:in `save'
The problem seems to stem from using self.class.counter_cache_options
here are my models:
class A < ActiveRecord::Base
is_impressionable :counter_cache => true
has_many :comments
end
class B < ActiveRecord::Base
is_impressionable :counter_cache => true
belongs_to A
end
now it wont work:
b = B.first
b.a.comments shows undefined method comments for A.
but b.a works fine.
if is_impressionable class method is been called after all association declaration then it works fine.
class B < ActiveRecord::Base
belongs_to A
is_impressionable :counter_cache => true
end
then all will work fine
NB: I am using rails 3.2.2 with impressionist 1.1.1
Hi. I'm enjoying my time with Impressionist so far. With Devise I overrode the Devise::SessionsController to get login impressions (logout, failed passwords, whatever) It works great.
class DemoSessionController < Devise::SessionsController
def create
if not @current_member.nil?
impressionist(@current_member, :unique => [:session_hash])
end
super
end
end
However I'm trying to get the impression data itself. I want to get all impressions for all logins/users for a date range (1 week) and group them by impressions.created_at date with a custom function to determine if the created_at date is within a daily range. e.g. I want to chart the login counts for each day in the last week, maybe even by specific user_id.
I can go and write some queries of my own (there's no Impressions Model) to retrieve this, but I thought I would ask if there was a secret method to get the impression data itself. The impressionist_count method is limited to only returning the size of impressions based on the set criteria.
Thanks.
Method names are too long. This should be consolidated into a single method with options hash
My app is crashing and this is what Passenger says the problem is
superclass mismatch for class Impression
Any ideas?
I don't know if this is right for the issues section but I've been trying to scope my model based on impressions (most viewed), i haven't been able to figure a way around, i i wish someone can help me figure this out or probably create a pull request for that.
¿Is this possible at all?
My use case consists of tracking impressions from banners, that are not served from a controller but from a view helper. I could consider using a rails cell if this is possible.
Thanks!
And also thanks for the great work.
log the session id for each request. Will help filter out duplicates
At the moment the code takes the name of the Controller and assumes that there's a Model of the same name.
Line 81 of impressionist_controller.rb:
:impressionable_type => controller_name.singularize.camelize,
Line 11 of /lib/impressionist/models/active_record/impression.rb:
impressionable_class = self.impressionable_type.constantize
This will fail if there's a "PostController" but no "Posts" model.
Steps to reproduce:
1/ Delete "Posts" model.
2/ rake spec
Expected behavior:
That the controller saves itself as the type ie. impressionable_type is "self.class.to_s" and impression.rb doesn't try and call constantize a model that doesn't exist.
I'm having some issues with Resque and Impressionist.
My Model
class Presentation < ActiveRecord::Base
has_one :video
is_impressionable
def create_slides
Resque.enqueue(ConvertSlides, self.id, pdf.path)
end
end
My worker fails.
undefined local variable or method is_impressionable' for #<Class:0x00000101f772e8> /Users/joshcrowder/rails/rails3/arcticfox/app/models/presentation.rb:10:in
class:Presentation'
Any ideas why? What do I have todo to get this wroking?
I'm using Rails 3.2.8 with Mongoid.
I tried to use :filter => :session_hash but it didn't work.
everytime I hit F5, the count increment in the view.
when I look at query in logs, i get this
database=mydb_development command={:count=>"impressions", :query=> {"impressionable_id"=>"50a720712b225bd8e2000001", "impressionable_type"=>"Mymodel", "impressionable_field"=>{"$in"=>[:impressions, nil]}, "session_hash"=>{"$ne"=>nil}}} (1.6191ms)
data insertion have done just fine, and I could get request.session_options[:id].
Hi, I'm using this awesome plugin, but I've encountered a little problem when doing the migration, the mysql2 gem returns:
Mysql2::Error: BLOB/TEXT column 'session_hash' used in key specification without a key length: CREATE INDEX poly_session_index
ON impressions
(impressionable_type
, impressionable_id
, session_hash
)
I've found a stackoverflow with an anwser about this error: http://stackoverflow.com/questions/1827063/mysql-error-key-specification-without-a-key-length
I'm already dont know how can I fix this whitout creating other problems when using this plugin. This error was ocurred to anyone else, or just me ?
Thanks in advance.
Ruby 1.9.2p290
Rails 3.1.1
Linux Mint (Ubuntu) 11.10
MySQL2 gem
I'm having trouble running this on rails 3.2.8 and I'm out of ideas.
.../gems/activerecord-3.2.8/lib/active_record/dynamic_matchers.rb:50:in `method_missing': undefined local variable or method `is_impressionable' for #<Class:0x007fe365fb4f00> (NameError)
/app/models/user.rb:3:in `<class:User>'
/app/models/user.rb:1:in `<top (required)>'
Here is my class:
class User < ActiveRecord::Base
is_impressionable
end
In a controller:
impressionist :actions=>[:show,:index]
works fine.
What am I missing?
To get the unique_impression_count and such to work I had to group by every column in the table. Didn't need this for sqlite.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.