簡體   English   中英

Mailboxer / Rails:“ sender =”的未定義方法

[英]Mailboxer/Rails: Undefined method for 'sender='

我已經在這個問題上奴役了一天半。 我正在使用Mailboxer gem創建一個非常干燥的消息傳遞系統; 一個與示例相同的示例-https: //github.com/RKushnir/mailboxer-app-只是從這個寶石開始。

實際上,我的計算機上有兩個存儲庫彼此相鄰。 郵箱特定的模型,遷移,初始化程序,所有我能找到的東西。 這包括帶有name操作的User模型。 我什至嘗試用attr_accessible弄亂Notification模型。

數據庫是相同的。

在將對話保存在示例應用程序中之后,當我嘗試在控制台/種子中創建消息時,這非常簡單。 對話保存后,我運行:

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生成的,並且與示例應用程序相同。

這里看看Mailboxer gem send_message方法您會發現它很有用。

您也可以使用內置的sender.message方法發送郵件

sender = User.find(1)
receiver = User.find(2) 
sender.send_message(receiver,"Subject", "Body")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM