我正在尝试让 Mailboxer gem 在 Rails 3.1 应用程序中工作......我的新消息功能正在工作,但回复对话一直给我一个undefined method 'is_trashed?' for nil:NilClass
错误。
我一直在关注 gem 网站上的自述信息,here,并查看示例邮箱应用程序here。
这是我的控制器:
class ConversationsController < ApplicationController
before_filter :authenticate_user!
helper_method :mailbox, :conversation
def show
@conversation ||= mailbox.conversations.find(params[:id])
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
conversation = current_user.reply_to_conversation(conversation, *message_params(:body)).conversation
redirect_to conversation
end
def trash
conversation.move_to_trash(current_user)
redirect_to :back
end
def untrash
conversation.untrash(current_user)
redirect_to :back
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
这是我的回复表格:
<%= simple_form_for :message, url: [:reply, conversation] do |f| %>
<%= f.input :body, as: :text, :input_html => { :cols => 50, :rows => 3 } %>
<div >
<%= f.button :submit, "Send", class: 'btn btn-primary' %>
</div>
<% end %>
新的对话正在工作,但由于某种原因,我不断收到reply_to_conversation
功能上的错误。任何帮助将非常感激!