# Why I can't update data, but I can insert data into new mode

**URL:** <https://www.ruby-forum.com/t/why-i-cant-update-data-but-i-can-insert-data-into-new-mode/117753>\
**Category:** Ruby\
**Created:** [October 19, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/why-i-cant-update-data-but-i-can-insert-data-into-new-mode/117753 "2007-10-19T22:40:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zlai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b3f665/32.png) [@zlai](https://www.ruby-forum.com/u/zlai)\
**Post date:** [October 19, 2007, 10:40pm UTC](https://www.ruby-forum.com/t/why-i-cant-update-data-but-i-can-insert-data-into-new-mode/117753/1 "2007-10-19T22:40:49Z")

</div>

why I can’t update data, but I can insert data into new model.  
like this:  
if File.find\_by\_id(id)  
file=File.find\_by\_id(id)  
else  
file=File.new

file.name=name  
file.save

there is a problem, when there don’t find id, there is no problem, But  
when find id, update the field,  
there is Error, there said: undefined method ‘name=’  
why? who can help me? Thanks!!

---

<div class="post-metadata">

**Author:** ![zlai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b3f665/32.png) [@zlai](https://www.ruby-forum.com/u/zlai)\
**Post date:** [October 19, 2007, 10:59pm UTC](https://www.ruby-forum.com/t/why-i-cant-update-data-but-i-can-insert-data-into-new-mode/117753/2 "2007-10-19T22:59:31Z")

</div>

File may be an unfortunate name for your ActiveRecord class since  
it’s also a built in ruby class.

when you do find\_by\_id (same as just find BTW) your getting your  
ActiveRecord class instance and when you do File.new your getting an  
instance of the built in ruby class which does not contain a “name=”  
method

that’s what I’m guessing anyway… checkout the RoR group;-)

Tim

On Oct 19, 2007, at 1:40 PM, OnRails R. wrote:

> ## there is a problem, when there don’t find id, there is no problem, But when find id, update the field, there is Error, there said: undefined method ‘name=’ why? who can help me? Thanks!!
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Be who you are and say what you feel, because those who mind don’t  
matter and those who matter don’t mind.

- Dr. Seuss

---

<div class="post-metadata">

**Author:** ![zlai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b3f665/32.png) [@zlai](https://www.ruby-forum.com/u/zlai)\
**Post date:** [October 20, 2007, 1:45am UTC](https://www.ruby-forum.com/t/why-i-cant-update-data-but-i-can-insert-data-into-new-mode/117753/3 "2007-10-20T01:45:46Z")

</div>

On Oct 19, 4:40 pm, OnRails R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## there is a problem, when there don’t find id, there is no problem, But when find id, update the field, there is Error, there said: undefined method ‘name=’ why? who can help me? Thanks!!
> 
> Posted viahttp://www.ruby-forum.com/.

you did not define ‘name’

file.name = “name”  
file.save

not tested

---

<div class="post-metadata">

**Author:** ![zlai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/b3f665/32.png) [@zlai](https://www.ruby-forum.com/u/zlai)\
**Post date:** [October 20, 2007, 1:50am UTC](https://www.ruby-forum.com/t/why-i-cant-update-data-but-i-can-insert-data-into-new-mode/117753/4 "2007-10-20T01:50:27Z")

</div>

On Oct 19, 4:40 pm, OnRails R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## there is a problem, when there don’t find id, there is no problem, But when find id, update the field, there is Error, there said: undefined method ‘name=’ why? who can help me? Thanks!!
> 
> Posted viahttp://www.ruby-forum.com/.

OOPS!!! my bad

there is no name method for name=

there is a rename method

File.rename(“old\_file\_name”, “new\_file\_name”)
