2014-02-26 42 views
2

我有mailboxer gem設置,當我訪問/對話時,我收到一個undefined method參與者''錯誤指向與索引對話控制器。我向索引操作添加了一個會話實例變量,該變量將包含用戶的所有收件箱郵件。NoMethodError未定義的方法'參與者'

有人可以發現我的錯誤在我的定義?

對話控制器:

helper_method :mailbox, :conversation 

    def index 
     @conversations ||= current_user.mailbox.inbox.all 
    end 

    def reply 
     current_user.reply_to_conversation(conversation, *message_params(:body, :subject)) 
     redirect_to conversation 
    end 

    def trash_folder     
     @trash ||= current_user.mailbox.trash.all   
     end 


    def create 
     recipient_emails = conversation_params(:recipients).split(',') 
     recipients = User.where(email: recipient_emails).all 

     conversation = current_user. 
     send_message(recipients, *conversation_params(:body, :subject)).conversation 

     redirect_to conversation 
    end 

    def reply 
     current_user.reply_to_conversation(conversation, *message_params(:body, :subject)) 
     redirect_to conversation 
    end 

    def trash 
     conversation.move_to_trash(current_user) 
     redirect_to :conversations 
    end 

    def untrash 
     conversation.untrash(current_user) 
     redirect_to :conversations 
    end 

    private 

    def mailbox 
     @mailbox ||= current_user.mailbox 
    end 

    def conversation 
     @conversation ||= mailbox.conversations.find(params[:id]) 
    end 

    def conversation_params(*keys) 
     fetch_params(:conversation, *keys) 
    end 

    def message_params(*keys) 
     fetch_params(:message, *keys) 
    end 

    def fetch_params(key, *subkeys) 
     params[key].instance_eval do 
     case subkeys.size 
     when 0 then self 
     when 1 then self[subkeys.first] 
     else subkeys.map{|k| self[k] } 
     end 
     end 
    end 
    end 

路線:

resources :users do |user| 

end 

resources :messages do 
    member do 
    post :new 
    end 
end 
resources :conversations do 
    member do 
    post :reply 
    post :trash 
    post :untrash 
    end 
    collection do 
    get :trashbin 
    post :empty_trash 
    end 
end 
+0

你會得到什麼確切的錯誤信息?一個完整的錯誤信息將包括接收者(例如,'undefined method'中的''foo'''for'foo':String')以及發生錯誤的文件和行號。 –

+0

錯誤來自index,'@conversations || = current_user.mailbox.inbox.all'確切的錯誤信息是# NoMethodError – xps15z

+0

您好,您是否添加了'acts_as_messageable'你的用戶模型?另外,您是否手動創建對話模型?如果你這樣做,這可能是問題。郵箱安裝腳本應爲您處理該配置。 – winston

回答

1

我終於可以重現您的問題,我解決它通過運行:

rails g mailboxer:install 

rake db:migrate 

您可能需要在db中對現有的conversations表進行一些操作。

+0

是的,那裏已經有了。 – xps15z

+0

我終於可以重現您收到的錯誤,請查看答案。 – raviolicode

+0

我第一次開始使用郵箱時,我遵循了該步驟。我只是重複了這一步,我收到了同樣的錯誤。我發佈的控制器不起作用,但是如果我從github示例恢復到提供的控制器,那麼該頁面就可以工作。 – xps15z

相關問題