我的 routes.rb 文件中有以下代码。
resources :users do
member do
get :following,:followers
end
collection do
put :activate_email
end
end
我有一个这样的用户电子邮件激活链接:
<%= link_to "Activate",activate_email_users_url(email_token: @user.email_token),method: :put %>
当我点击激活链接时,这是生成的 url
http://localhost:3000/users/activate_email?email_token=WWNvMN-r_lXgovrQiDlSSQ
更新:好的,所以我想我知道问题是什么。当我在我的 gmail 中查看包含 link_to 的激活电子邮件的 html 源时,没有
数据方法='放'. 所以这似乎是问题所在。它总是发送一个默认的 GET 请求而不是 PUT。这是我的 user_mailer/registration_confirmation.html.erb 文件
<%= javascript_include_tag "application" %>
</head>
请点击以下链接激活您的电子邮件 <%= link_to "Activate",activate_email_users_url(email_token: @user.email_token), method: :put %>
这给出了以下错误:
未定义的方法“protect_against_forgery?” 为了 #导致此错误。有没有办法解决 ?所以,代码 <%= javascript_include_tag "application" %>