Rails is generating account activation URL's with a period, instead of a question mark. I see this happening consistently in both the mailer preview and the rails log. Example link:
http://localhost:3000/account_activations/Cm4OyFOwosBcGZ67qg49nQ/edit.example@railstutorial.org
From routes.rb:
resources :account_activations, only: [:edit]
From users_controller.rb:
def create
@user = User.new(user_params)
if @user.save
UserMailer.account_activation(@user).deliver_now
flash[:info] = "Please check your email to activate your account."
redirect_to root_url
else
render 'new'
end
end
From account_activation.html.erb:
<%= link_to "Activate", edit_account_activation_url(@user.activation_token, @user.email) %>
From user.rb (method to create and assign the digest):
def create_activation_digest
self.activation_token = User.new_token
self.activation_digest = User.digest(activation_token)
end
From user_mailer_preview.rb:
def account_activation
user = User.first
user.activation_token = User.new_token
UserMailer.account_activation(user)
end
The url_route
only takes one param: id
. What you want to do is this:
edit_account_activation_url(@user.activation_token, email: @user.email)
This will give you params[:id]
and params[:email]
in your controller to use.
The reason is that every resourceful url_helper actually expects n or n+1 arguments (where n is a number of named params in the route), with the last argument being format of the route:
user_path(@user, :json) #=> /users/1.json
(Actually the signature is just url_helper(*args)
, wrong arity exception is thrown from inside of the helper)
If you want to add extra get parameters, you need to pass an extra hash as already stated by nzfinab:
user_path(@user, hello: :there) #=> /users/1?hello=there
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.