Вот простая модель.
class Event
include Mongoid::Document
field :name, type: String
field :schedule, type: String
field :description, type: String
field :active, type: Boolean, default: true
key :name
end
1.Мы создаем и событие
ruby-1.9.2-p0 > event = Event.new(:name => "event1")
=> #<Event _id: event1, _type: nil, _id: "event1", name: "event1", schedule: nil, description: nil, active: true>
ruby-1.9.2-p0 > event.save!
=> true
2. Ноу позволяет найти событие
ruby-1.9.2-p0 > event = Event.find("event1")
=> #<Event _id: event1, _type: nil, _id: "event1", name: "event1", schedule: nil, description: nil, active: true>
3.Так обновить атрибуты события
ruby-1.9.2-p0 > event.update_attributes!(:name => "new name")
=> true
4.Позволяет найти событие
ruby-1.9.2-p0 > event = Event.find("new name")
Mongoid::Errors::DocumentNotFound: Document not found for class Event with id(s) new name.
5.Параметры не найдены, но старый все еще сохраняется
ruby-1.9.2-p0 > event = Event.find("event1")
=> #<Event _id: event1, _type: nil, _id: "event1", name: "event1", schedule: nil, description: nil, active: true>
Что я делаю не так?Я надеюсь, что это не ошибка.