[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Prevent attributes vs local variable conflict in activerecord models

Simone Carletti

10/16/2007 4:34:00 PM

Hello, I need a suggestion about a possible best practice.
Consider the following piece of code

class ThumbnailImage < ActiveRecord::Base
# more code

public
#
#
#
def request_thumbnail(args = {})
width = args[:width] ||= nil
height = args[:height] ||= nil

# do something
# with local variables width and height
# and get job object

# update image details
self.width = job.width
self.height = job.height
self.requested_at = job.submission_time
self.webthumb_id = job.id

return append_to_fetch_queue()
end

end

As you can see in the same method I have both a local variable called
width and an activerecord table column called width.
To prevent weird behaviors I used self to identify local object
accessor method but I don't know if this is the best practice to
prevent local variables to conflict with active record attributes.

How do you usually handle this case?

1 Answer

mortee

10/16/2007 6:17:00 PM

0