将邮件过滤为未读和读取导轨

时间:2016-10-13 05:37:40

标签: ruby-on-rails ruby controller haml mailboxer

我想在网站中过滤我的邮件以进行阅读和未阅读。当我点击未读的按钮时,必须有未读的消息,这应该和读取一样。我使用rails来制作它。

在这段代码中,我得到“param丢失或值为空:mailboxer_message”错误

index.html.haml

  = button_to "Read", messages_path(unread: 1), class: 'btn btn-success'
  = button_to "Unread", messages_path(unread: 0), class: 'btn btn-success'

messages.controller.rb

class MessagesController < ApplicationController
      def index
        add_breadcrumb "Inbox", :messages_path
        @messages = current_admin.mailbox.inbox.order('updated_at DESC')
        if params[:unread] == 1
          @messages = mailbox.inbox(:unread => true)
        elsif params[:unread] == 0
          @messages = mailbox.inbox(:unread => false)
        end
      end
       .......
      def message_params
        params.require(:mailboxer_message).permit(:conversation_id, :body, :attachment, :recipients, :subject, :unread)
      end

1 个答案:

答案 0 :(得分:1)

默认情况下,

button_tomethod设置为POST。您可以按method进行更改。然后,您可以通过params传递参数。

= button_to "Read", messages_path, class: 'btn btn-success', method: :get, params: { unread: 1 }
= button_to "Unread", messages_path, class: 'btn btn-success', method: :get, params: { unread: 0 }