Reputation:
I want to filter my messages in the website to read and unread. when i click to the unread button there must be just unread messages and this should work as well as reads. I use rails to make this.
In this code i get "param is missing or the value is empty: mailboxer_message" error
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
Upvotes: 0
Views: 308
Reputation: 66
button_to
set method
to POST
at default. You can change it by method
. Then you can pass parameters by 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 }
Upvotes: 1