【rails】Uncaught ReferenceError: $ is not defined

背景

Ajaxを組み込み、フォロー機能を実装している際に発生する。 エラーの原因は$ is not definedより、jQueryに関連すると推測。

解決方法

  • jQueryをGemfileに記載。
  • app/assets/javascripts/applicationに//= require jquery を記載。 ただし、require_treeより前に組み込む。

今後への対策

rails new appをするだけで、jQueryはGemfileに自動で記載されているものと勘違いを起こしていた。 jQueryは、自分でgem "jquery-rails" とGemfileに記述すること!!!

参考サイト

Uncaught ReferenceError: $ is not defined【rails】 - Qiita

Rails Tutorial Ch. 13でNameError: uninitialized constant Micropost::PictureUploaderが出た時の対処法

試したこと

springを再起動する

$ sudo spring stop
$ bundle update

結果

無事にエラーが直りました

参考サイト

【13章】Railsチュートリアル中にNameError: uninitialized constant Micropost::PictureUploaderが出た時の対処法 - 紙一重の積み重ね

production環境でのメール認証でエラーが出現する際に試したこと

背景

herokuで作成中のwebアプリでユーザー登録を実行する際に、 sign upボタンを押すと、We're sorry, but something went wrong.が表示されるページにリダイレクトされてしまう。

heroku logs --tailを実行してログの収集を行う。

原因

ログを追った結果、以下の文言を発見。

Net::SMTPFatalError (550 Unauthenticated senders not allowed)

SendGridでのエラーに起因しているようだ。 この文章をググると、以下の公式サイトが出てきた。 https://sendgrid.com/docs/for-developers/sending-email/smtp-errors-and-troubleshooting/#550-unauthenticated-senders-not-allowed

解決するには、以下を実行すれば良さそう。

you’ll want to make sure that you’ve configured your setup to connect to smtp.sendgrid.net using authentication, and that the credentials you’re using are the same credentials you use to login to the SendGrid.

解決方法

config/environments/production.rb SMPTの:user_nameを'SENDGRID_USERNAME'に、:passwordを'SENDGRID_PASSWORD'にそれぞれ変更。 そうすると、設定した通りにユーザー登録の為の認証メールが届いた。

注意事項として、本番運用するアプリケーションでは、暗号化されていないIDやパスワードのような重要なセキュリティ情報はソースコードに直接書き込まない。環境変数に記述し、そこからアプリケーションに読み込む。今回の場合は、そうした変数はSendGridアドオンが自動的に設定してくれる。

技術的に学べたこと

  • herokuでのデバック方法

    • heroku logs
    • heroku logs --tail
    • heroku run rails c
  • 環境変数

    • まだよく理解できていない。

191126_日報

取り組んだこと

学んだこと

  • “fixed mindset”

    • the belief that your abilities are fixed and that the world is just a series of tests that show you how good you are
    • success comes from proving how great you are.
    • feel smart when they don't make mistakes
    • try to blame the world when things go bad
    • be afraid to try hard
  • "growth mindset"

    • the belief that everything come through effort and that the world is full of interesting challenges that can help you learn and grow
    • success comes from growing
    • feel smart when they struggle with something for a long time and then finally figure it out
    • look to see what they can change about themselves
    • be afraid of not trying
  • this difference between these mindsets appear in all sorts of places - in relationships, CEO and even in sports.

  • your mindset itself can be changed

    • the first step to getting better is believing you can get better
  • Rubyでクラスメソッドの定義

    • self
  • mapメソッド

    • ブロックの戻り値が新しい配列の各要素になる