1

使用mailboxer gem,我在对话控制器中定义了回复操作,但是在回复消息时,它说找不到该操作。我得到错误AbstractController::ActionNotFound at /conversations/2/reply The action "reply" could not be found for ConversationsController

我重新启动服务器存在相同的错误。

对话控制器:

  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

回复表单视图:

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

路线:

 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
4

1 回答 1

2

看起来您end在控制器的开头有一个额外的东西,这会过早地关闭您的课程。

  helper_method :mailbox, :conversation

  def index
    @conversations ||= current_user.mailbox.inbox.all
    end    <--- superfluous end
    end
于 2014-02-27T16:40:08.173 回答