Ruby 在 rails。 Mailboxer,将多个对话移至垃圾箱。 #<Array 的未定义方法
Ruby on rails. Mailboxer, move multiple conversations to trash. Undefined method for #<Array
我正在努力使用复选框将多个项目发送到垃圾文件夹。我得到一个
undefined method `move_to_trash' for #<Array:0x007...etc...
move_to_trash
适用于单个对话。
我在部分呈现的每个对话旁边都有一个复选框,以及一个用于删除所有选中对话的按钮。
无论如何,我的对话控制器:
def trash_multiple
@convo = mailbox.conversations.find(params[:trash_id])
@convo.move_to_trash(current_user)
redirect_to mailbox_inbox_path
end
部分复选框,位于每个对话旁边:
<%= check_box_tag "trash_id[]", conversation.id %>
ID 正确。
形式:
<div class="message-cont">
<div class="col-md-8">
<%= form_tag trash_multiple_conversations_path, method: :post do %>
<%= submit_tag "Trash selected" %>
<div class="panel-body">
<% if is_conversation %>
<%= render 'conversations/form' %>
<% else %>
<div class="msg-cnter">
<%= render partial: 'conversations/conversation', collection: messages %>
</div>
<% end %>
<% end %>
</div>
</div>
</div>
我的路线:
resources :conversations do
member do
post :reply
post :trash
post :untrash
end
collection do
get :trashbin
post :empty_trash
post :trash_multiple
end
end
任何关于让它在数组中工作的提示都将不胜感激,谢谢。
解决方案:
将控制器更改为:
def trash_multiple
params[:trash_id].each do |element|
@convo = mailbox.conversations.find(element)
@convo.move_to_trash(current_user)
end
redirect_to mailbox_inbox_path
end
如@wpp 所述,已修复此问题。
move_to_trash works fine on single conversations.
我的猜测是您想对数组的每个元素调用 move_to_trash
方法:
array.each do |element|
element.move_to_trash
end
或更短:
array.map(&:move_to_trash)
试试这个
@convo.each {|c| c.move_to_trash(current_user) }
我正在努力使用复选框将多个项目发送到垃圾文件夹。我得到一个
undefined method `move_to_trash' for #<Array:0x007...etc...
move_to_trash
适用于单个对话。
我在部分呈现的每个对话旁边都有一个复选框,以及一个用于删除所有选中对话的按钮。
无论如何,我的对话控制器:
def trash_multiple
@convo = mailbox.conversations.find(params[:trash_id])
@convo.move_to_trash(current_user)
redirect_to mailbox_inbox_path
end
部分复选框,位于每个对话旁边:
<%= check_box_tag "trash_id[]", conversation.id %>
ID 正确。
形式:
<div class="message-cont">
<div class="col-md-8">
<%= form_tag trash_multiple_conversations_path, method: :post do %>
<%= submit_tag "Trash selected" %>
<div class="panel-body">
<% if is_conversation %>
<%= render 'conversations/form' %>
<% else %>
<div class="msg-cnter">
<%= render partial: 'conversations/conversation', collection: messages %>
</div>
<% end %>
<% end %>
</div>
</div>
</div>
我的路线:
resources :conversations do
member do
post :reply
post :trash
post :untrash
end
collection do
get :trashbin
post :empty_trash
post :trash_multiple
end
end
任何关于让它在数组中工作的提示都将不胜感激,谢谢。
解决方案:
将控制器更改为:
def trash_multiple
params[:trash_id].each do |element|
@convo = mailbox.conversations.find(element)
@convo.move_to_trash(current_user)
end
redirect_to mailbox_inbox_path
end
如@wpp 所述,已修复此问题。
move_to_trash works fine on single conversations.
我的猜测是您想对数组的每个元素调用 move_to_trash
方法:
array.each do |element|
element.move_to_trash
end
或更短:
array.map(&:move_to_trash)
试试这个
@convo.each {|c| c.move_to_trash(current_user) }