0
我作出了悄悄話系統和我使用狀態機知道哪裏是消息。state_machine與收件箱和發送的消息
這是我的模型:
class Message
include Mongoid::Document
include Mongoid::Timestamps::Created
#fields
field :subject, :type => String
field :body, :type => String
field :place, :type => String
field :has_been_read, :type => String
# Relationships
belongs_to :sender, :class_name => 'User', :inverse_of => :messages_sent
belongs_to :receiver, :class_name => 'User', :inverse_of => :messages_received
#state machine has been read message?
state_machine :has_been_read, :initial => :unread do
event :read_message do
transition :from => :unread, :to => :read
end
event :mark_unread do
transition :from => :read, :to => :unread
end
end
#state machine status can be in_box, sent, draft, trash, spam
end
用戶模型:
class User
include Mongoid::Document
include Mongoid::Timestamps::Created
.
.
.
has_many :messages_sent, :class_name => 'Message', :inverse_of => :sender
has_many :messages_received, :class_name => 'Message', :inverse_of => :receiver
.
.
.
end
1º如何的消息是在同一時間上sent
或inbox
的地方嗎?
2º什麼初始狀態對發送者和接收者用戶的消息?
很抱歉,但我是新手與state_machine gem
非常感謝您
非常感謝您! – hyperrjas
我的榮幸。很高興它有幫助。 –