更新Heroku生产数据库中的字符串属性



尝试更改我的生产Heroku数据库中的字符串描述之一,但不知道如何做。

运行heroku run rails console

Location.where(id: 2)

我有这个:

#<Location id: 2, name: "Camera 2", lat: -118.238275051117, long: 34.0491659368589, created_at: "2014-05-23 22:02:57", updated_at: "2014-05-23 22:02:57", description: "Convention Center">

我正试图将"description:"字符串从"Convention Center"更新为"Hollywood",以及long: float属性。

有没有一种方法可以在Heroku控制台做,而不必擦除和重新播种整个东西?

我想的是Location.update(2) { location.update_attribute :description, "Hollywood" }

Location.update(2) { location.update_attribute :lat, -117.1335235 }

但是这些是不正确的。我希望这是一个简单的行命令。

谢谢大家的帮助!

试试这个:

Location.find(2).update_attributes(description: "Hollywood", lat: 2393, long: 384)

其中latlong是你的整数/浮点数

登录到heroku控制台后,您可以尝试更新所需的属性,而无需重新播种整个对象。

location = Location.find(2)
location.update_attribute(:description, "description text")
location.update_attribute(:lat,1.4535643)

update_attribute和update_attributes的主要区别是update_attribute不会重新播种对象,其时间戳也不会更新。

最新更新