在Controller中找不到错误“回复”操作,但它存在于文件中

时间:2014-02-27 16:05:22

标签: ruby-on-rails mailboxer

使用邮箱gem我在Conversations控制器中定义了回复操作,但是在回复邮件时它说无法找到操作。我收到错误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

1 个答案:

答案 0 :(得分:2)

看起来您在控制器的开头有一个额外的end,这会过早关闭您的班级。

  helper_method :mailbox, :conversation

  def index
    @conversations ||= current_user.mailbox.inbox.all
    end    <--- superfluous end
    end