我正在尝试让Mailboxer gem在Rails 3.1应用程序中工作......我有新的消息功能正常工作,但回复一个对话一直给我一个undefined method 'is_trashed?' for nil:NilClass
错误。
我一直关注宝石网站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
功能上遇到错误。任何帮助将不胜感激!
答案 0 :(得分:0)
显然,服务器只需要重新启动...不确定原因,因为这只是在控制器和视图方面。它现在正在运作!