# Method "movie\_file=" can someone explain this to me please?

**URL:** <https://www.ruby-forum.com/t/method-movie-file-can-someone-explain-this-to-me-please/114129>\
**Category:** Rails\
**Created:** [September 8, 2007, 10:37am UTC](https://www.ruby-forum.com/t/method-movie-file-can-someone-explain-this-to-me-please/114129 "2007-09-08T10:37:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 8, 2007, 10:37am UTC](https://www.ruby-forum.com/t/method-movie-file-can-someone-explain-this-to-me-please/114129/1 "2007-09-08T10:37:45Z")

</div>

I’m using this method, adapted from a similar one for pictures, and it  
works fine but i don’t really understand how:

def movie\_file=(input\_data)  
self.filename = input\_data.original\_filename  
self.content\_type = input\_data.content\_type.chomp  
self.file\_data = input\_data.read  
end

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?

thanks  
max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 8, 2007, 11:34am UTC](https://www.ruby-forum.com/t/method-movie-file-can-someone-explain-this-to-me-please/114129/2 "2007-09-08T11:34:40Z")

</div>

On 08 Sep 2007, at 10:37, Max W. wrote:

> 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.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 8, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/method-movie-file-can-someone-explain-this-to-me-please/114129/3 "2007-09-08T16:06:09Z")

</div>

On Sep 8, 1:37 am, Max W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## 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).

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [September 9, 2007, 3:58pm UTC](https://www.ruby-forum.com/t/method-movie-file-can-someone-explain-this-to-me-please/114129/4 "2007-09-09T15:58:48Z")

</div>

Peter De Berdt wrote:

> On 08 Sep 2007, at 10:37, Max W. wrote:

> def movie\_file=(x)  
> #code  
> end
> 
> The above is used to SET the movie file

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!
