現在簡単なECサイトアプリを作成しています。
注文レコードを作成したあとにActionMailerを利用してメールを送信するようにしています。
送られてきたメールには注文レコードに関連した情報が表示されています。
ただ画像表示だけがうまくいきません(m_ m)
わかる方がいらっしゃれば教えていただきますようよろしくお願いいたします(m _m)
###期待する動作
- ActionMailerを利用したメールに画像を表示させたい
(商品画像の保存先は db/fixtures/ファイル名
になっている)
###動作環境
OS:mac
Ruby:2.3.5
Ruby on Rails: 4.2.5
(ActionMailerを利用、送信メールアドレスは自分のGmailメールアドレスを利用)
デプロイ先:AWS
###参考サイト
###試したこと
参考サイト(2)のサイトをもとに app/config/environment/production.rb
の設定を変更しましたがうまくいきませんでした(m_ _m)
###該当のソースコード
config/environments/production.rb
ruby
1Rails.application.configure do 2 config.cache_classes = false 3 4 # Do not eager load code on boot. 5 config.eager_load = true 6 7 config.log_level = :info 8 9 # Show full error reports and disable caching. 10 config.consider_all_requests_local = true 11 config.action_controller.perform_caching = false 12 13 # enable disp images sent by ActionMailer 14 config.action_controller.asset_host = '自分のIP' 15 config.action_mailer.asset_host = config.action_controller.asset_host 16 config.action_mailer.default_url_options = { host: '自分のIP' } 17 18 config.action_mailer.default_url_options = { host: "自分のIP" } 19 config.action_mailer.delivery_method = :smtp 20 config.action_mailer.smtp_settings = { 21 address: 'smtp.gmail.com', 22 port: 587, 23 user_name: '自分のメールアドレス', 24 password: ENV['gmail_pass'], 25 authentication: 'plain' 26 } 27 # Print deprecation notices to the Rails logger. 28 config.active_support.deprecation = :log 29end
app/mailers/order_mailer.rb
ruby
1class OrderMailer < ApplicationMailer 2 default from: "さんぷる <自分のgmailアドレス>" 3 4 def send_when_create(order) 5 @order = order 6 mail to: @order.user.email, 7 subject: "ご注文ありがとうございました" 8 9 end 10end
app/views/order_mailer/order_completed.html.erb
ruby
1<!DOCTYPE html> 2<html> 3<head> 4 <meta charset="utf-8"> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 6 <link rel="stylesheet" href=""> 7 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 8</head> 9<body> 10 11</body> 12</html> 13 14<h3><%= @order.user.email %>様へ</h3> 15 16<div>下記の注文を受け付けました。ご注文いただきありがとうございました</div> 17<div class="row col-md-6 col-md-offset-3""> 18 <table class="table table-hover"> 19 <% @order.orderitems.each do |orderitem| %> 20 <tr> 21 <td class="text-center"><%= image_tag orderitem.item.mainImage.url, size: '100x100' %></td> 22 . 23 . 24 . 25 </tr> 26 <% end %> 27 </table> 28</div>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/04 07:06
2018/10/04 10:14
2018/10/07 00:51