Pergunta

I have mailboxer gem setup and when I visit /conversations I receive a undefined methodparticipant' ` The error points to the Conversations controller with the index. I added a conversations instance variable to the index action that will contain all of the user’s inbox messages.

Can someone spot where I went wrong in my definition?

Conversations controller:

 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

Routes:

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
Foi útil?

Solução

I could finally reproduce your issue, I solved it by running:

rails g mailboxer:install

and

rake db:migrate

You will probably need to do something about your existing conversations table in your db.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top