Reputation: 1
In my registrations/edit.html.erb
view file I'd like to add a link to delete a current avatar (if it's attached). I've ended up with something like this:
<% if current_user.avatar.attached? %>
<%= link_to "Remove avatar", { action: :remove_avatar }, method: :put %>
<% end %>
In custom registrations_controller
(inherited from Devise::RegistrationsController
) I defined a method :remove_avatar
:
def remove_avatar
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
resource.avatar.purge_later
end
But I've got this error, which is probably caused by a lack of routes settings.
No route matches {:action=>"remove_avatar", :controller=>"registrations", :locale=>:ru}
What can I do to be able to link_to this method? Thank you.
Upvotes: 0
Views: 282
Reputation: 26
Probably you would need something like this
put "remove_avatar", to: "registrations#remove_avatar"
in your routes.rb file.
Maybe it can get messier than this because of your directory structure, but it should work
Upvotes: 0