BrowserCMS and Paperclip

BrowserCMS can โ€œdeleteโ€ objects, which basically sets the: deleted attribute to true. Initially, Paperclip runs the following code to retrieve all objects of a particular class:

Person.connection.select_values(Person.send(:construct_finder_sql, :select => 'id')) 

This may return [1, 2, 3]. Even if, say, 3: deleted, set to true. Paperclip then uses ActiveRecord to retrieve all People objects using the previous list of identifiers. Unfortunately, BrowserCMS does not return objects marked as deleted, so Paperclip fades: "Could not find Person with ID = 3".

I'm not sure where to go from here, except for the monkey patch. Thoughts?

+4
source share
1 answer

So, the hacker way to resolve this (which can easily turn into a paper clip fork) is to change the above code to just ready:

 Person.all.collect(&:id) 

or

 Person.connection.select_values(Person.send( :construct_finder_sql, :select => 'id', :conditions => { :deleted => false } )) 

The first parameter simply forces Paperclip to execute the request through Rails, which essentially goes through BrowserCMS, thereby using its limitations (i.e.: without seeing any deleted entries). The second option makes almost the same request, but does not contain records deleted by BCMS.

I believe the first option is best, since it allows BCMS to control the request, so if something changes, your monkey patch will not break.

+1
source

All Articles