M
Matthew D Moss
I'm learning Rails, and trying to setup image upload in a form. As part
of that, my image model looks something like this:
class Image < ActiveRecord::Base
validates_presence_of :content_type
validates_format_of :content_type, :with => /^image/, :message =>
"must be an image"
def image_file=(arg)
self.content_type = arg.content_type.chomp
end
end
Okay, so the above basically works. But I wondered why the author I
borrowed this from used "self." instead of @ -- I thought both would
essentially reference an instance variable.
So I replaced the one line to look like this:
@content_type = arg.content_type.chomp
and it fails, triggering my validation checks.
What gives?
of that, my image model looks something like this:
class Image < ActiveRecord::Base
validates_presence_of :content_type
validates_format_of :content_type, :with => /^image/, :message =>
"must be an image"
def image_file=(arg)
self.content_type = arg.content_type.chomp
end
end
Okay, so the above basically works. But I wondered why the author I
borrowed this from used "self." instead of @ -- I thought both would
essentially reference an instance variable.
So I replaced the one line to look like this:
@content_type = arg.content_type.chomp
and it fails, triggering my validation checks.
What gives?