前提・実現したいこと
railsでユーザー登録する時にユーザーに対してメールを送って、ユーザーがそのメールをクリックしたらユーザー登録できるみたいなことを実装してるのですが、
OpenSSL::SSL::SSLError in UsersController#create SSL_connect returned=1 errno=0 state=error: wrong version number
とのエラーが出ていて、
ググったとこと、、Ruby(Net::HTTP?)が SSL証明書を見つけることができなくて、HTTPS 接続に失敗しているのが原因らしい,SSL証明書が必要?な気がする
ユーザーを新規登録する際にエラーが出ます
該当のソースコード
ruby
1 UserMailer.account_activation(@user).deliver_now 2ここにハイライトされましたが根本的な問題はここではない気がする
ruby
1development.rb 2 3 Rails.application.configure do 4 # Settings specified here will take precedence over those in config/application.rb. 5 6 # In the development environment your application's code is reloaded on 7 # every request. This slows down response time but is perfect for development 8 # since you don't have to restart the web server when you make code changes. 9 config.cache_classes = false 10 11 # Do not eager load code on boot. 12 config.eager_load = false 13 14 # Show full error reports. 15 config.consider_all_requests_local = true 16 17 # Enable/disable caching. By default caching is disabled. 18 # Run rails dev:cache to toggle caching. 19 if Rails.root.join('tmp', 'caching-dev.txt').exist? 20 config.action_controller.perform_caching = true 21 config.action_controller.enable_fragment_cache_logging = true 22 23 config.cache_store = :memory_store 24 config.public_file_server.headers = { 25 'Cache-Control' => "public, max-age=#{2.days.to_i}" 26 } 27 else 28 config.action_controller.perform_caching = false 29 30 config.cache_store = :null_store 31 end 32 33 # Store uploaded files on the local file system (see config/storage.yml for options). 34 config.active_storage.service = :local 35 36 # Don't care if the mailer can't send. 37 38 # config.action_mailer.raise_delivery_errors = true 39 # コメントアウトすることでdelelop環境からもメールを送信する設定に 40 41 host = 'b9c7c936bba34db686385a83af09e0a0.vfs.cloud9.ap-northeast-1.amazonaws.com' # ここをコピペすると失敗します。自分の環境のホストに変えてください。 42 # クラウドIDEの場合は以下をお使いください 43 config.action_mailer.default_url_options = { host: host, protocol: 'https' } 44 # localhostで開発している場合は以下をお使いください 45 # config.action_mailer.default_url_options = { host: host, protocol: 'http' } 46 47 config.action_mailer.perform_caching = false 48 49 # Print deprecation notices to the Rails logger. 50 config.active_support.deprecation = :log 51 52 # Raise an error on page load if there are pending migrations. 53 config.active_record.migration_error = :page_load 54 55 # Highlight code that triggered database queries in logs. 56 config.active_record.verbose_query_logs = true 57 58 # Debug mode disables concatenation and preprocessing of assets. 59 # This option may cause significant delays in view rendering with a large 60 # number of complex assets. 61 config.assets.debug = true 62 63 # Suppress logger output for asset requests. 64 config.assets.quiet = true 65 66 # Raises error for missing translations. 67 # config.action_view.raise_on_missing_translations = true 68 69 # Use an evented file watcher to asynchronously detect changes in source code, 70 # routes, locales, etc. This feature depends on the listen gem. 71 config.file_watcher = ActiveSupport::EventedFileUpdateChecker 72 config.hosts.clear 73 74 config.action_mailer.asset_host = 'b9c7c936bba34db686385a83af09e0a0.vfs.cloud9.ap-northeast-1.amazonaws.com/' 75 config.action_mailer.default_url_options = { host: 'localhost:3000' } 76 config.action_mailer.raise_delivery_errors = true 77 config.action_mailer.delivery_method = :smtp 78 config.action_mailer.smtp_settings = { 79 address: 'smtp.gmail.com', 80 port: 587, 81 domain: 'gmail.com', 82 authentication: :login, 83 user_name: '個人情報@gmail.com', 84 password: '個人情報', 85 enable_starttls_auto: true, 86 openssl_verify_mode: 'none', 87 ssl: true, 88 tls: true 89 90 } 91end 92
ruby
1#users_controller.rb 2 3class UsersController < ApplicationController 4 before_action :logged_in_user,only: [:index,:edit,:update,:destroy] 5 # メソッド名は基本シンボルで呼び出す 6 # 一回before_actionをコメントアウトして 7 # テストかけてちゃんと失敗するか確かめるべき 8 before_action :correct_user, only: [:edit,:update] 9 before_action :admin_user, only: :destroy 10 11 # => GET /users 12 def index 13 @users = User.paginate(page: params[:page]) 14 # pageの中にpageが格納されていて、何番目 15 # のページにいるか取得できる 16 end 17 18 def show 19 @user = User.find(params[:id]) 20 end 21 22 def new 23 @user = User.new 24 end 25 26 def create 27 @user = User.new(user_params) 28 if @user.save 29 # before_createでトークンがセットされてる 30 # => メールオブジェクトを生成する条件は 31 # 整ってる 32 UserMailer.account_activation(@user).deliver_now 33 # メイラーメソッド呼び出し 34 # deliver_nowは送信するメソッド 35 # 引数に渡されたユーザーに対して送信できるのかな? 36 flash[:info] = "Please check your email to activate your account." 37 redirect_to root_url 38 # log_in @user 39 # flash[:success] = "Welcome to the Sample App!!" 40 # redirect_to @user 41 # # user_path(@user) 42 # # user_path(@user.id) 43 # # user_path(1) => /users/1 44 else 45 render 'new' 46 end 47 end 48 49 # GET /users/:id/edit 50 def edit 51 @user = User.find(params[:id]) 52 # => app/views/users/edit.html.erb 53 end 54 55 # PATCH /users/:id 56 def update 57 @user = User.find(params[:id]) 58 if 59 @user.update(user_params) 60 flash[:success] = "Profile update" 61 redirect_to @user 62 else 63 render 'edit' 64 end 65 end 66 67 def destroy 68 User.find(params[:id]).destroy 69 flash[:success] = "User deleted" 70 redirect_to users_url 71 end 72 73 private 74 # これよりしたに書いたメソッドはこのファイルの 75 # 外からアクセスできない(基本的に) 76 77 def user_params 78 params.require(:user).permit(:name,:email,:password,:password_confirmation) 79 end 80 81 # ログインしてなかったらログインページに遷移する 82 def logged_in_user 83 unless logged_in? 84 # ログインしてるかどうか確かめるメソッド 85 store_location 86 # 遷移したいページを覚えとく 87 flash[:danger] = "Please log in." 88 redirect_to login_url 89 end 90 end 91 92 def correct_user 93 @user = User.find(params[:id]) 94 redirect_to(root_url) unless current_user?(@user) 95 # current_user?メソッド呼び出し 96 # form_withから受け取ったパラメーターのuserと 97 # セッションまたは、クッキーからのユーザー 98 # が一致してるかしてないか 99 100 end 101 102 def admin_user 103 redirect_to(root_url) unless current_user.admin? 104 end 105end 106 107 108
試したこと
ググったらSSL証明書がないから、安全な通信を担保できないとかあったので
https://blog.takuros.net/entry/2014/05/17/172257
上記の記事を参考にしたところ、記事通りの挙動はしましたが結果は変わらずでした
$ wget http://curl.haxx.se/ca/cacert.pem
上記のコマンドで一応SSL証明書は手に入れた、、??
https://stackoverflow.com/questions/4528101/ssl-connect-returned-1-errno-0-state-sslv3-read-server-certificate-b-certificat
上記の記事を参考にしたところ
SSL_CERT_FILE=/opt/local/etc/certs/cacert.pem rails generate jquery:install
を実行したら
Running via Spring preloader in process 3195 Could not find generator 'jquery:install'. Run `rails generate --help` for more options.
と出てきました、、
補足情報(FW/ツールのバージョンなど)
cloud9 ubunts
ruby 2.6.3
rails 6.0.0
主はテックキャンプのカリキュラムを終えた程度のひよこです
回答1件
あなたの回答
tips
プレビュー