S
Simone Carletti
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?
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?