在registrations/edit.html.erb
查看文件中,我想添加一个链接以删除当前的头像(如果已附加)。我最终得到了这样的东西:
<% if current_user.avatar.attached? %>
<%= link_to "Remove avatar", { action: :remove_avatar }, method: :put %>
<% end %>
自定义registrations_controller
(继承自Devise::RegistrationsController
),我定义了一种方法:remove_avatar
:
def remove_avatar
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
resource.avatar.purge_later
end
但是我遇到了此错误,这可能是由于缺少路由设置引起的。
没有路由匹配{:action =>“ remove_avatar”,:controller =>“ registrations”,:locale =>:ru}
我该怎么做才能链接到此方法?谢谢。
可能您需要这样的东西
put "remove_avatar", to: "registrations#remove_avatar"
在routes.rb文件中。
也许由于您的目录结构,它可能比这更混乱,但它应该可以工作