If i have Image class and i’d like to add ‘create_thumbnail’ method to
it, which will later be called from product controller, where to put
this method and how to call it?
I’ve tried putting it inside image controller and image model, then call
it like Image.create_thumbnail, but it didn’t work - undefined method
`create_thumbnail’ for Image:Class.
If i have Image class and i’d like to add ‘create_thumbnail’ method to
it, which will later be called from product controller, where to put
this method and how to call it?
I’ve tried putting it inside image controller and image model, then call
it like Image.create_thumbnail, but it didn’t work - undefined method
`create_thumbnail’ for Image:Class.
Do you want a class method or an instance method?
Class methods look like this:
class Image
def self.create_thumbnail
# return a thumbnail image here
# You probably need to pass some arguments to this method
# so it knows what to do
end
end
but instance methods look like this:
class Image
def create_thumbnail
# return a thumbnail image of this object
end
end
Notice there’s no “self.” prefixed to the method name here.