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

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

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

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Git

Gitはオープンソースの分散バージョン管理システム(DVCS)です。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

Ruby on Rails

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

Q&A

解決済

1回答

1189閲覧

git push heroku masterする際に発生した rake aborted!を解決したい

ikutyan46

総合スコア18

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Git

Gitはオープンソースの分散バージョン管理システム(DVCS)です。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

Ruby on Rails

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

0グッド

0クリップ

投稿2020/06/25 13:12

#実現したいこと
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

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

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

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

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

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

guest

回答1

0

ベストアンサー

下記に示す、NoMethodErrorのto_symは、どこのファイルに対して怒っているのでしょうか?

ここです。

rb

1# production.rb 2config.action_mailer.delivery_method = ENV['delivery_method'].to_sym

投稿2020/06/25 13:18

Mugheart

総合スコア2344

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

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

ikutyan46

2020/06/25 13:29

Mugheartさん 早速、ありがとうございます。ご提示いただいた部分がシンボルになっていない、ということは分かったのですが、その部分をどう変えるのがよろしいでしょうか?Mugheartさんのお考えをお聞かせください^^
Mugheart

2020/06/25 13:38

エラーの内容は「nil に to_sym というメソッドは定義されていません」というものです。 問題なのは ENV['delivery_method'] が nil になっている事だと思いますので、 環境変数 delivery_method を用意する事で解決するのではないでしょうか。
ikutyan46

2020/06/25 16:02

Mugheartさん ありがとうございます。こちら、application.ymlのシンボルを文字列に修正し、その後production.rbのdelivery_methodの部分の.to_symを削除。その後git add, commit,pushしてもう一度git push heroku masterすることで解決しました!ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問