Я создал этот же поток для моего сайта.Вот пример того, что вы можете сделать:
добавить в config / rout.rb (обратите внимание, что маршрутизация могла бы быть лучше, но я сделал это некоторое время назад)
scope :path => '/users', :controller => 'users' do
match 'verify_email' => :verify_email, :as => 'verify_email'
match 'edit_account_email' => :edit_account_email, :as => 'edit_account_email'
match 'update_account_email' => :update_account_email, :as => 'update_account_email'
end
добавить в app / controllers / users_controller.rb
def edit_account_email
@user=current_user
end
def update_account_email
@user=current_user
@user.password_not_needed=true
@user.email=params[:address]
if @user.save
flash[:notice]="your login email has been successfully updated."
else
flash[:alert]="oops! we were unable to activate your new login email. #{@user.errors}"
end
redirect_to edit_user_path
end
def verify_email
@user=current_user
@address=params[:address]
UserMailer.confirm_account_email(@user, @address).deliver
end
app / mailers / user_mailer.rb
class UserMailer < ActionMailer::Base
def confirm_account_email(user, address)
@user = user
@address = address
mail(
:to=>"#{user.name} <#{@address}>",
:from=>"your name <'your_email@domain.com'>",
:subject=>"account email confirmation for #{user.name}"
)
end
end
app / views / user_mailer / verify_account_email.html.erb
<p>you can confirm that you'd like to use this email address to log in to your account by clicking the link below:</p>
<p><%= link_to('update your email', update_account_email_url(@user, :address=>@address)) %></p>
<p>if you choose not to confirm the new address, your current login email will remain active.