Domanda

sto prendendo un primo sguardo a Monk e le API / Redis Ohm e ho una domanda semplice. E 'possibile aggiornare gli attributi di oggetti del modello utilizzando 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

Utilizzando l'API Ohm posso effettuare le seguenti operazioni

require 'ohm'
Ohm.connect
Ohm.redis.set :foo, "bar"
Ohm.redis.set :foo, "bat"

Non riesco a trovare alcuna info nella documentazione su come raggiungere questo obiettivo. Grazie in anticipo!

È stato utile?

Soluzione

Non sono sicuro Capisco perfettamente quello che stai chiedendo circa, ma con il seguente codice l'attributo viene aggiornato.

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

Allora ottengo:

#<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">

Quindi, l'attributo name viene aggiornato.

Altri suggerimenti

Si dovrebbe essere in grado di farlo utilizzando un #save normale. Puoi pubblicare più contesto per scoprire perché non funziona?


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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top