#実現したいこと
git push heroku masterする際に、rake aborted
(rakeが中断された!)が発生し、デプロイができない状況です。
#前提
Herokuschedulerを利用して、毎日1回全てのUserに対して、リマインドメールを送る機能を実装するためのタスクとして、ActionMailerの実装と、必要なGemfileのインストール、コードの記述を行っています。これまで発生したことがないため、今回の実装に対する何かしらのエラーだと思われます。
下記に示す、NoMethodErrorのto_sym
は、どこのファイルに対して怒っているのでしょうか?解決の方向性含め、お分かりの方がいらっしゃれば、ご教示頂けますと幸いです。
terminal
1remote: rake aborted! 2remote: NoMethodError: undefined method `to_sym' for nil:NilClass
#環境
Rails:5.2.4
DB:PostgreSQL
Rubyのbuildpackはインストール済
(heroku create --buildpack https://github.com/heroku/heroku-buildpack-ruby.git)
#試したこと
普通にActionMailerの実装しても良いが、Heroku上で環境変数を指定しないとGitHubでパスワードが公開されてしまうとのこと。それを防ぐ方法をググったところ、figaroというgemをインストールすると良いとのことだったので、インストールしてbundleしました。
rails generate figaro:install
するとconfig/application.yml
(と.gitignoreに/config/application.yml)が追加されたので、前者のファイルに下記を記述。
エラーでは、「NoMethodError」「to_sym」とあったので、シンボルを作れていなかったのでは?と思い、同ファイルで下記を修正しコミット。
delivery_method: :smtp
に、:
がなかったので追記したのと、smtp_authentication: :plain
に、:
がなかったので追記しました。
しかし結果は変わらず。というところで止まってしまいました。
Teriminal
1# Add configuration values here, as shown below. 2# 3# pusher_app_id: "2954" 4# pusher_key: 7381a978f7dd7f9a1117 5# pusher_secret: abdc3b896a0ffb85d373 6# stripe_api_key: sk_test_2J0l093xOyW72XUYJHE4Dv2r 7# stripe_publishable_key: pk_test_ro9jV5SNwGb1yYlQfzG17LHK 8# メール送信サーバの設定(gmail) 9delivery_method: :smtp 10smtp_enable_starttls_auto: true 11smtp_address: smtp.gmail.com 12smtp_port: 587 13smtp_domain: gmail.com 14smtp_authentication: :plain 15smtp_user_name: (自分のアドレス)@gmail.com 16smtp_password: (2段階認証で定めたアプリパスワード) 17 18# production: 19# stripe_api_key: sk_live_EeHnL644i6zo4Iyq4v1KdV9H 20# stripe_publishable_key: pk_live_9lcthxpSIHbGwmdO941O1XVU
#エラー文・関連性の高そうなコード
エラー
user$ git push heroku master Enumerating objects: 803, done. Counting objects: 100% (802/802), done. Delta compression using up to 8 threads Compressing objects: 100% (284/284), done. Writing objects: 100% (771/771), 230.32 KiB | 12.79 MiB/s, done. Total 771 (delta 490), reused 710 (delta 456) remote: Compressing source files... done. remote: Building source: remote: remote: -----> Ruby app detected remote: -----> Installing bundler 2.0.2 remote: -----> Removing BUNDLED WITH version in the Gemfile.lock remote: -----> Compiling Ruby/Rails remote: -----> Using Ruby version: ruby-2.6.5 remote: -----> Installing dependencies using bundler 2.0.2 remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment remote: The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`. remote: Fetching gem metadata from https://rubygems.org/......... (中略) remote: Bundle complete! 39 Gemfile dependencies, 92 gems now installed. remote: Gems in the groups development and test were not installed. remote: Bundled gems are installed into `./vendor/bundle` remote: Removing rack (2.2.2) remote: Bundle completed (5.34s) remote: Cleaning up the bundler cache. remote: -----> Installing node-v10.15.3-linux-x64 remote: -----> Installing yarn-v1.16.0 remote: -----> Detecting rake tasks remote: -----> Preparing app for Rails asset pipeline remote: Running: rake assets:precompile remote: done. remote: rake aborted! remote: NoMethodError: undefined method `to_sym' for nil:NilClass remote: /tmp/build_36aeef685518c1e10af0e29640aec0b6/config/environments/production.rb:4:in `block in <main>' (中略) remote: /tmp/build_36aeef685518c1e10af0e29640aec0b6/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>' remote: Tasks: TOP => environment remote: (See full trace by running task with --trace) remote: remote: ! remote: ! Precompiling assets failed. remote: ! remote: ! Push rejected, failed to compile Ruby app. remote: remote: ! Push failed remote: Verifying deploy... remote: remote: ! Push rejected to quiet-escarpment-59252. remote: To https://git.heroku.com/quiet-escarpment-59252.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'https://git.heroku.com/quiet-escarpment-59252.git'
application_mailer.rb
class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' end
alert_mailer.rb(自分で設定したものです)
Ruby
1class AlertMailer < ApplicationMailer 2 def send_alert(user) 3 mail to: user.email, subject: '練習記録を登録しましょう!' 4 end 5end
send_alert_mail.rake
Ruby
1namespace :send_alert_mail do 2 desc "登録アラートメールの送信" 3 task main: :environment do 4 # puts "Hello World" 5 6 User.all.each do |user| 7 AlertMailer.send_alert(user).deliver_later 8 end 9 end 10 puts "done." 11end
production.rb
ruby
1Rails.application.configure do 2 # Settings specified here will take precedence over those in config/application.rb. 3 config.action_mailer.raise_delivery_errors = true 4 config.action_mailer.delivery_method = ENV['delivery_method'].to_sym 5 config.action_mailer.default_url_options = { host: 'quiet-escarpment-59252.herokuapp.com(アプリのURL)'} 6 config.action_mailer.smtp_settings = { 7 enable_starttls_auto: ENV['smtp_enable_starttls_auto'], 8 address: ENV['smtp_address'], 9 port: ENV['smtp_port'], 10 domain: ENV['smtp_domain'], 11 authentication: ENV['smtp_authentication'], 12 user_name: ENV['smtp_user_name'], 13 password: ENV['smtp_password'] 14 } 15(中略) 16 17 # Store uploaded files on the local file system (see config/storage.yml for options) 18 config.active_storage.service = :local 19 20 # Mount Action Cable outside main process or domain 21 # config.action_cable.mount_path = nil 22 # config.action_cable.url = 'wss://example.com/cable' 23 # config.action_cable.allowed_request_origins = [ 'http://example.com', /http://example.*/ ] 24 25 # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 26 # config.force_ssl = true 27 28 # Use the lowest log level to ensure availability of diagnostic information 29 # when problems arise. 30 config.log_level = :debug 31 32 # Prepend all log lines with the following tags. 33 config.log_tags = [ :request_id ] 34 35 # Use a different cache store in production. 36 # config.cache_store = :mem_cache_store 37 38 # Use a real queuing backend for Active Job (and separate queues per environment) 39 # config.active_job.queue_adapter = :resque 40 # config.active_job.queue_name_prefix = "tt_manager_#{Rails.env}" 41 42 config.action_mailer.perform_caching = false 43 44 # Ignore bad email addresses and do not raise email delivery errors. 45 # Set this to true and configure the email server for immediate delivery to raise delivery errors. 46 # config.action_mailer.raise_delivery_errors = false 47 48 # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 49 # the I18n.default_locale when a translation cannot be found). 50 config.i18n.fallbacks = true 51 52 # Send deprecation notices to registered listeners. 53 config.active_support.deprecation = :notify 54 55 # Use default logging formatter so that PID and timestamp are not suppressed. 56 config.log_formatter = ::Logger::Formatter.new 57 58 # Use a different logger for distributed setups. 59 # require 'syslog/logger' 60 # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 61 62 if ENV["RAILS_LOG_TO_STDOUT"].present? 63 logger = ActiveSupport::Logger.new(STDOUT) 64 logger.formatter = config.log_formatter 65 config.logger = ActiveSupport::TaggedLogging.new(logger) 66 end 67 68 # Do not dump schema after migrations. 69 config.active_record.dump_schema_after_migration = false 70end 71
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/25 13:29
2020/06/25 13:38
2020/06/25 16:02