0

私はこの問題に1日半悩まされてきました。私は Mailboxer gem を使用して、非常に単純なメッセージング システムを作成しています。サンプルと同じもの - https://github.com/RKushnir/mailboxer-app - この宝石から始めましょう。

私は文字通り、両方のリポジトリをコンピューター上で隣り合わせに配置しています。メールボックス固有のモデル、移行、初期化子、私が見つけることができるすべて。nameこれには、アクションを含む User モデルが含まれます。Notificationでモデルをいじってみましたattr_accessible

データベースは同一です。

サンプル アプリで会話を保存した後、コンソール/シードでメッセージを作成しようとすると、非常に簡単です。会話が保存されたら、次を実行します。

n = Message.new
n.sender = User.find(1)
n.subject = 'Hi'
n.body = 'Hello there.'
n.conversation_id = Conversation.find(1).id
n.save

そしてブーム。美しく機能します。一方、私のアプリは同じように機能します。畑に着くまでsender

送信者を設定しようとすると:

n.sender = User.find(1)

次のエラーが表示されます。NoMethodError: undefined method 'sender=' for #<Message:0x00000101708eb8>

どうして??

これは私を夢中にさせています。誰かが助けを貸してくれるなら、本当に感謝しています。前もって感謝します。

メッセージ/通知スキーマ:

  create_table "notifications", force: true do |t|
    t.string   "type"
    t.text     "body"
    t.string   "subject",              default: ""
    t.integer  "sender_id",                            null: false
    t.integer  "conversation_id"
    t.boolean  "draft",                default: false
    t.datetime "updated_at",                           null: false
    t.datetime "created_at",                           null: false
    t.integer  "notified_object_id"
    t.string   "notified_object_type"
    t.string   "notification_code"
    t.string   "attachment"
    t.boolean  "global",               default: false
    t.datetime "expires"
  end

  add_index "notifications", ["conversation_id"], name: "index_notifications_on_conversation_id", using: :btree

これは gem が生成するもので、サンプル アプリと同じです。

4

1 に答える 1

0

ここで Mailboxer gem sent_message メソッドを見てください。役に立つかもしれません。

send_message メソッドに組み込まれているメールボックスを使用してメッセージを送信することもできます

sender = User.find(1)
receiver = User.find(2) 
sender.send_message(receiver,"Subject", "Body")
于 2014-02-24T06:07:07.743 に答える