사이트/레일즈 앱에 로그인하기 전에 사용자가 자신의 사용자 계정을 확인해야하는 레일스 4.2.0 앱에서 로직을 설정하려고합니다. 기본적으로, 나는 사람이 이메일/패스워드를 입력하고 그들의 서명을 할 수있는 sign up 양식을 가지고있다. 이 과정에서 확인 토큰을 사용하여 이메일 주소로 이메일을 보내면 확인을위한 링크가 제공됩니다. 확실하게 확인 토큰을 사용하여 DB의 부울 값을 false에서 true로 변경합니다. 나는 지금까지 구현 한 것을 게시 할 것이다.레일을 사용하여 확인 이메일을 보내는 방법은 무엇입니까?
users_controller.rb
def create
@user = User.new(user_params)
if @user.save
# send confirmation email after user has been created.
@user.send_confirmation
session[:user_id] = @user.id
redirect_to root_url, notice: "Thank you for signing up!"
else
render "new"
end
end
def confirm
@user = User.find_by_confirmation_token!(params[:id])
if @user.update_attributes(confirmed: true)
redirect_to login_path
end
end
confirmation.text.erb이
To confirm your account, click the URL below.
<%= user_url(@user.confirmation_token) %>
<%= url_for(controller: 'users', action: 'confirm') %>
If you did not request your account creation, just ignore this email and your account will not be created.
routes.rb
Rails.application.routes.draw do
resources :articles do
resources :comments
end
get 'resume' => 'resume#index'
get 'signup' => 'users#new'
get 'login' =>'sessions#new'
get 'logout' => 'sessions#destroy'
# the below route led to a rails routing error
# get 'confirm' => 'users/:confirmation_token#confirm'
resources :users
resources :sessions
resources :password_resets
# route to hopefully get confirmation link working :-/
match '/users/:confirmation_token', :to => 'users#confirm', via: [:post, :get]
# test route
match 'users/foo', :to => 'users#foo', via: [:post, :get]
root "articles#index"
# Added below route for correct "resumé" spelling
get 'resumé', :to =>"resume#index"
# get 'about#index'
get 'about' => 'about#index'
get 'contact' => 'contact#contact'
resources :about
resources :contact
match ':controller(/:action(/:id))(.:format)', via: [:post, :get]
다음과 같습니다/plataformatec/devise/master/Devise/Models/Confirmable – kasperite