【问题标题】:error 'reply' action not found in Controller, but it is present in file在控制器中找不到错误“回复”操作,但它存在于文件中
【发布时间】:2014-02-27 16:05:21
【问题描述】:

使用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

【问题讨论】:

    标签: ruby-on-rails mailboxer


    【解决方案1】:

    您的控制器开头似乎有一个额外的end,这会过早关闭您的课程。

      helper_method :mailbox, :conversation
    
      def index
        @conversations ||= current_user.mailbox.inbox.all
        end    <--- superfluous end
        end
    

    【讨论】:

    • 谢谢。我将多余的一端移到了控制器的底部。
    • 那么这是否解决了您的问题?您接受了答案,但您的评论似乎另有说明。您能否发布其余的控制器代码,以便我们了解为什么需要额外的 end
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多