Search code examples
ruby-on-railsrailstutorial.orgmailer

Why is Rails putting a period(dot) before the query string in URL's, instead of a question mark?


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

Solution

  • 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.