Question

I'm trying to get Mailboxer gem working in a Rails 3.1 app... I have the New message function working, but replying to a conversation keeps giving me an undefined method 'is_trashed?' for nil:NilClass error.

I've been following the read me info on the gem site, here, and looking at the example mailboxer app here.

Here's my controller:

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

And here is my reply form:

<%= 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 %>

New conversations are working, but for some reason I keep getting errors on the reply_to_conversation functionality. Any help would be much appreciated!

Was it helpful?

Solution

Apparently, the server just needed to be restarted... Not sure why, because this was only on the controller and view side of things. It's working now!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top