Question

Using the mailboxer gem I have the reply action defined in the Conversations controller, however when replying to a message it says the action cannot be found. I get the error AbstractController::ActionNotFound at /conversations/2/reply The action "reply" could not be found for ConversationsController

I restarted server the same error is present.

Conversations Controller:

  helper_method :mailbox, :conversation

  def index
    @conversations ||= current_user.mailbox.inbox.all
    end
    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 trash
    conversation.move_to_trash(current_user)
    redirect_to :conversations
    end

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

    def empty_trash
      current_user.mailbox.trash.each do |conversation|    conversation.receipts_for(current_user).update_all(:deleted => true)
      end
     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

Reply form view:

 <%= form_for :message, url: [:reply, conversation] do |f| %>
 <%= f.text_area :body %>
 <%= f.submit "Send Message", class: 'btn btn-primary' %>
 <%= submit_tag 'Clear Reply Box', type: :reset, class: 'btn btn-danger' %>
 <% end %>

Routes:

 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
Was it helpful?

Solution

It looks like you have an additional end at the beginning of your controller, which would prematurely close your class.

  helper_method :mailbox, :conversation

  def index
    @conversations ||= current_user.mailbox.inbox.all
    end    <--- superfluous end
    end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top