controller
def create
UserMailer.reset_password_instructions(@user).deliver
end
user.rb
class User < ActiveRecord::Base
before_create :generate_reset_password_token
devise :database_authenticatable,
:rememberable,
:validatable,
:recoverable,
:trackable,
:timeoutable
private
def generate_reset_password_token
raw, enc = Devise.token_generator.generate(self.class, :reset_password_token)
@raw_confirmation_token = raw
self.reset_password_token = enc
self.reset_password_sent_at = Time.now.utc
end
end
user_mailer.rb
class UserMailer < ApplicationMailer
include Devise::Mailers::Helpers
default from: 'no-reply@identt.co'
def reset_password_instructions(resource, opts={})
@resource = resource
@token = @resource.reset_password_token
mail(to: @resource.email, subject: "Reset Password Instructions")
end
end
reset_password_instructions.html.erb
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
At this point, when the user is manually created by the administrator, the Password resetLink is sent to the email address that I see with MailCatcheror letter_opener.
http://lvh.mehaps000/users/password/edit?reset_password_token=6a8bc4683fc9e5dfcc789f94f9b6bd2b1c44fd857f13662d0f0d1f6212022f81
I click the link, and she successfully took me to edit the password page. When I submit the form, due to ivalidation failure with the message Reset password token is invalid.
What I miss here ...
UPDATE:
My Development.rb looks like this:
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.digest = true
config.assets.raise_runtime_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "lvh.me", :port => 1025 }
config.action_mailer.default_url_options = { host: 'lvh.me', port: 3000 }
config.domain = 'lvh.me'
end