ユーザーメッセージ(ダイアログ)を使用してアプリを作成する必要があります。私はこの方法でこの問題を解決しました:
app / models / conversation.rb
class Conversation < ActiveRecord::Base
belongs_to :user
belongs_to :interlocutor
has_many :messages
end
app / models / message.rb
class Message < ActiveRecord::Base
belongs_to :conversation
belongs_to :user
attr_accessible :message
end
app / models / user.rb
class User < ActiveRecord::Base
...
def conversations
Conversation.uniq.joins(:messages)
.where("conversations.user_id = ?", self.id)
.where("conversations.interlocutor_id = ?", self.id)
.order("messages.created_at DESC")
end
end
会話方式で混乱しています。これはPHPの方法のようなもので、柔軟性はありません。
レールで書き換えることはできますか?多分それはAR関係である可能性がありますか?
ありがとう。