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

O

OnRails Ruby

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!!
 
B

bbiker

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

you did not define 'name'

file.name = "name"
file.save

not tested
 
B

bbiker

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

OOPS!!! my bad

there is no name method for name=

there is a rename method

File.rename("old_file_name", "new_file_name")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top