i’m using the new fields this creates, such as filename, content_type
etc, in my other methods, and it all works, but what’s the meaning of a
method ending in an equals sign like this? I’ve had errors with other
classes where it says things like “missing method ‘story=’” in my story
controller (or maybe it was the model).
I’m guessing that this is a standard rails way of doing something but
it’s got me puzzled…at a guess, i’d say that it’s like an add-on to a
constructor, that gets called after the constructor is called, to add
some new fields to the object? Is that right?
classes where it says things like “missing method ‘story=’” in my
story
controller (or maybe it was the model).
It’s an assign method.
def movie_file #code
end
The above is used to GET the movie file
def movie_file=(x) #code
end
The above is used to SET the movie file
I’ll simplify a little, but suppose you don’t have a field movie_file
in your model (i.e. database table), you can use this method to
pretend it’s there. You then handle it with the variable “x” so that
it does something useful.
etc, in my other methods, and it all works, but what’s the meaning of a
max
Posted viahttp://www.ruby-forum.com/.
att_accessor is a way of defining “virtual” AR attributes or virtual
columns in a table, the canonical example being “password” and
“password_confirm” which are taken from a user’s registration form but
never saved to database (the hashed password and salt are saved).
ahhh…of course I always used attr_accessor in ruby (i’ve only done
a few bits of non-rails ruby coding) and forgot about the individual set
and get methods. That all makes sense now, thanks both!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.