質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

1241閲覧

Gmailを使ったメール認証のやり方について

galaxymaximum

総合スコア11

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2018/02/19 09:51

現在Gメールを使ったメール認証を行えるようにしているのですが、メールを送った後、ユーザーにどうさせればいいのかがわかりません。ちなみにupdateという単語が出てきますが、やろうとしているのはcreate時のものです。

appliction_mailer.rb

class ApplicationMailer < ActionMailer::Base default from: "aaa@gmail.com", bcc: "aaa@gmail.com", reply_to: "aaa@gmail.com" layout 'mailer' end

sample_mailer.rb

class SampleMailer < ApplicationMailer # Subject can be set in your I18n file at config/locales/en.yml # with the following lookup: # # en.sample_mailer.send_when_update.subject # def send_when_update(user) @user = user mail to: user.email, subject: '認証メールを送りました。' end end

usercontrollerのなかのcreateアクション

def create @user = User.new(user_params) if @user.save #@user.send_activation_email SampleMailer.send_when_update(@user).deliver flash[:info] = "メールアドレスに有効化メールを送りました。アカウントを有効化してください。" redirect_to root_url else render 'new' end end

development.rb

Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Do not eager load code on boot. config.eager_load = false # Show full error reports. config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=172800' } else config.action_controller.perform_caching = false config.cache_store = :null_store end config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { port: 587, address: 'smtp.gmail.com', domain: 'smtp.gmail.com', user_name: 'aaaa@gmail.com', password: 'ndnfjkbskbjn', authentication: 'login', enable_starttls_auto: true } # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. config.assets.debug = true # Raises error for missing translations # config.action_view.raise_on_missing_translations = true # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker end

send_when_update.html.erb

<!doctype html> <html lang="ja"> <head> <meta content="text/html; charset=UTF-8" /> <style type="text/css"> h2 { color: #e7454a; } p hr { color: #2d2a24; } </style> </head> <body> <h2><%= @user.name %> 様</h2> <hr /> <p> この度は「メールテスト運営局」を利用頂きましてありがとうございます。 </p> <p> ユーザー名: <%= @user.name %><br /> </p> <hr /> </body> </html>

send_when_update.text.erb

=============================== <%= @user.name %>様 =============================== この度は「メールテスト運営局」を利用頂きましてありがとうございます。 ユーザー名: <%= @user.name %> <h1>Sample App</h1> <p>Hi <%= @user.name %>,</p>

send_when_update.text.erbにリンクを貼っておき、それをユーザーが踏めばアカウントが有効化されるようにしたいのですが、どうすれば良いのでしょうか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問