无法弄清楚如何更新邮箱 is_read [英] cannot figure out how to update mailboxer is_read
问题描述
我正在使用邮箱管理器 gem 并且我正在尝试使用它,以便在我查看对话后(通过访问对话#show),我希望收据的 is_read 属性变为真.但是,在我发送回复之前,该属性不会变为真.我尝试使用以下行:
I am using the mailboxer gem and I am trying to make it so that after i look at a conversation (by accessing conversations#show), I want the is_read attribute of the receipt to turn true. However, the attribute will not turn true until I send a reply. I tried using the following line:
receipt.update_attributes(is_read: true)
但返回以下错误:
Error (ActiveRecord::ReadOnlyRecord)
我想我理解错误.我认为这是说该属性只能读取而不能更新.我的问题是,如果我转到对话#show 页面,如何实现让 is_Read 变为真的功能?
I think I understand the error. I think it is saying that the attribute can only be read and not updated. My question is, how do I implement the functionality to have is_Read turn true if i go to the conversations#show page?
推荐答案
不要更新 is_read 属性试试这个
Instead of updating the is_read attribute try this
#conversations_controller.rb
def show
@receipts = mailbox.receipts_for(conversation).not_trash
@receipts.mark_as_read
end
private
def mailbox
@mailbox ||= current_user.mailbox
end
def conversation
@conversation ||= mailbox.conversations.find(params[:id])
end
您还可以将整个对话标记为已读
You can also mark a entire conversation as read with
conversation.mark_as_read(current_user)
这篇关于无法弄清楚如何更新邮箱 is_read的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!