Rails rails console 对数据库的操作

asmcos · February 18, 2013 · Last by joinall replied at February 18, 2013 · 3490 hits

如何更改已有的数据库记录? 例如表名字 User User.new() 创建一个新的 User.all 列出所有的

如何更改 id=6 的某个字段?

自己搜索下 api 吧,现成的。

你的回答,提示太少;:-) 感谢!

update_attribute 不行吗?

User.find_by_id("6")

user = User.find(6) user.update_attribute(:name,"fuck") 或者 user.update_attributes({:name=>"fuck"})

user= User.find(6) user.name="fuck" user.save

You need to Sign in before reply, if you don't have an account, please Sign up first.