Feurio
March 12, 2008, 8:55pm
1
What is the right way to achieve something like this:
class Design < ActiveRecord::Base
belongs_to :card_collection
after_save :generate_images
has_one :background,
:as => :resourceable,
:class_name => “Resource”,
:conditions => [ ‘title = ?’, self.id ],
:dependent => :destroy
end
Everything here is working as expected. ONLY the conditions part is
not working…
The problem is that self.id is NOT the @my_design.id (the id of the
active record design instance), but the object_id of the instance. HOW
can I tell ActiveRecord that I want the @my_design.id ???
Thanks for any help!
Feurio
Feurio
March 12, 2008, 9:11pm
2
On 12 Mar 2008, at 19:54, Feurio wrote:
:conditions => [ 'title = ?', self.id ],
Set conditions to ‘title =#{self.id}’ (make sure it’s single quotes
not double quotes). Activerecord should interpolate it for you.
Fred
Feurio
March 16, 2008, 5:51pm
3
Hi Fred,
thanks for the hint. I finally found out how to get it work:
class Design < ActiveRecord::Base
belongs_to :card_collection
after_save :generate_images
has_one :background,
:as => :resourceable,
:class_name => “Resource”,
:conditions => [ ‘title = ?’, ‘#{self.id}’ ],
:dependent => :destroy
end
…by putting it in single quotes it worked.
Thanks.
Feurio
On 12 Mrz., 21:08, Frederick C. [email protected]