Skip to content

Friendly_id and impressionist 1.0.1 not recording impressionable id #27

adanacs opened this Issue Feb 17, 2012 · 8 comments

6 participants

adanacs commented Feb 17, 2012

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


but not


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 :)


Same problem here. Any ideas?


before_filter :only => [:show] do |controller|
params[:id] =

impressionist :actions => [:show]

Kind of ugly but it works now.

pekpon commented Mar 27, 2012

I have the same problem in Rails 3.2.0...

JapArt commented May 12, 2012

I have the same problem with Rails 3.2.1


Yep, having the same issue here, using friendly_id with slugged. Rails 3.1.1

Well, my option was to change the behavior of impressionist.
First changed the column impressionable_id to string.
Modified impressionable.rb, in line 13 I added:

if self.respond_to?(:friendly_id)
  has_many :impressions, :as => :impressionable, :finder_sql => {
      SELECT `impressions`.* FROM `impressions` WHERE `impressions`.`impressionable_id` = '#{slug}' AND `impressions`.`impressionable_type` = '#{self.class.to_s}'
  has_many :impressions, :as => :impressionable

This is not the best workaround, but works for me, maybe because I'm using impressionist in a "default" way for most of my models and controllers, but maybe not work in other situations. If someone know a better way to do that, please tell us :)

Another caveat, the specific SQL above sometimes return wrong, if for example you do @object.impressions.to_sql will return a wrong SQL, BTW @object.impressions will return the correct objects.

The impressionist_count method broken with "select", this is baaad...
For now I've commented the lines 47 to 49 (the line numbers change with the add above) in the impressionist_count method to work for me, while cant find a workaround.

For this situation, it needs to change to the impressionist_count method, set imps.all.size to imps.count (I dont know if I'm right, but this improve the SQL too)

Maybe someone find a better way to improve all this "behaviors" that are really dirty... thanks

pekpon commented May 23, 2012

I do this, in the controller:

def show
@article = Article.find(params[:id])

and its ok!



JapArt commented May 25, 2012

Works for me too. Thanks!

@acnalesso acnalesso closed this Jun 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.