I followed these instructions, but now I'm running into a problem. When I click my unsubscribe_url in the email, I get the following error:
No route matches [GET] "/newsletter_subscriptions/unsubscribe/b25a63f6e525deccd6bcd9e896c3321f"
This is how I setup my routes:
put 'newsletter_subscriptions/unsubscribe/:unsubscribe_hash' => 'newsletter_subscriptions#unsubscribe', :as => 'unsubscribe'
resources :newsletter_subscriptions
Why do I get a [GET]
error message when I'm actually using put
?
In my NewsletterSubscriptionsController I have
def unsubscribe
@newsletter_subscription = NewsletterSubscription.find_by_unsubscribe_hash(params[:unsubscribe_hash])
@newsletter_subscription.update_attribute(:active, false)
end
The link that should hit the unsubscribe
action in my controller is:
<%= link_to 'Unsubscribe', unsubscribe_url(@unsubscribe_hash), method: :put %>
When I inspect the link with browser dev tools it looks correct to me:
<a rel="nofollow" data-method="put" href="http://localhost:3000/newsletter_subscriptions/unsubscribe/b25a63f6e525deccd6bcd9e896c3321f">Unsubscribe</a>
I wonder why the link doesn't hit the unsubscribe action of my controller. If anyone can give me a push in the right direction, that would be wonderful. Thanks a lot!