tags:

views:

289

answers:

2

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!

A: 

You should be able to do it using a regular #save. Can you post more context to find out why it's not working?


event = Event[25]
event.name = "Updated name"
event.save

djanowski
A: 

I'm not sure I fully understand what you are asking about, but with the following code the attribute is updated.

require 'rubygems'
require 'ohm'

Ohm.connect

class Event < Ohm::Model
  attribute :name
  index :name
end

Event.create(:name => "A mistake made here...")

@event = Event.find(:name => "A mistake made here...").first
puts @event.inspect
@event.name = "I want to edit my mistake... but do not know how"
@event.save
puts @event.inspect

@event2 = Event.find(:name => "I want to edit my mistake... but do not know how").first
puts @event2.inspect

I then get:

#<Event:1 name="A mistake made here...">
#<Event:1 name="I want to edit my mistake... but do not know how">
#<Event:1 name="I want to edit my mistake... but do not know how">

So the name attribute is updated.

Kim Joar