是否可以使用 Ohm 和 Redis DB is Ruby 更新模型属性?
我第一次了解 Monk 和 Ohm/Redis API,我有一个简单的问题。是否可以使用 Ohm/Redis 更新模型对象的属性?
class Event < Ohm::Model
attribute :name
index :name
end
Event.create(:name => "A mistake made here...")
@event = Event.find(:id, 25)
@event.name = "I want to edit my mistake... but do not know how"
@event.save
使用 Ohm API 我可以执行以下操作
require 'ohm'
Ohm.connect
Ohm.redis.set :foo, "bar"
Ohm.redis.set :foo, "bat"
似乎无法在文档中找到有关如何完成此操作的任何信息。提前致谢!
I'm taking a first look at Monk and the Ohm/Redis APIs and I have a simple question. Is it possible to update attributes on model objects using Ohm/Redis?
class Event < Ohm::Model
attribute :name
index :name
end
Event.create(:name => "A mistake made here...")
@event = Event.find(:id, 25)
@event.name = "I want to edit my mistake... but do not know how"
@event.save
Using the Ohm API I can do the following
require 'ohm'
Ohm.connect
Ohm.redis.set :foo, "bar"
Ohm.redis.set :foo, "bat"
Can't seem to find any info in the docs about how to accomplish this. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否完全理解您所问的问题,但使用以下代码更新了属性。
然后我得到:
所以名称属性已更新。
I'm not sure I fully understand what you are asking about, but with the following code the attribute is updated.
I then get:
So the name attribute is updated.
您应该能够使用常规的
#save
来完成此操作。您可以发布更多上下文来找出它不起作用的原因吗?You should be able to do it using a regular
#save
. Can you post more context to find out why it's not working?