Skip to content

Commit

Permalink
高齢者が食事を撮影したら閲覧者にメールがいくようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
defaultcf committed Oct 18, 2017
1 parent acb69b8 commit 124ea1c
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
web: bin/rails server -p $PORT -b 0.0.0.0
worker: bundle exec sidekiq -C config/sidekiq.yml
3 changes: 3 additions & 0 deletions app/controllers/meals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def create

respond_to do |format|
if @meal.save
@user.followers.each do |follower|
UserMailer.notify_new_meal(follower, @user, @meal).deliver_later
end
format.html { redirect_to user_meals_path, notice: "Meal was successfully created." }
format.json { render :show, status: :created, location: @meal }
else
Expand Down
8 changes: 8 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class UserMailer < ApplicationMailer
def notify_new_meal(to_user, monitored, meal)
@to_user = to_user
@monitored = monitored
@meal = meal
mail(to: @to_user.email, subject: "#{monitored}さんが食事を撮影しました")
end
end
5 changes: 5 additions & 0 deletions app/views/user_mailer/notify_new_meal.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1><%= @monitored.profile.nickname %>さんが食事を撮影しました!</h1>

<%= image_tag @meal.img %>

<%= link_to "コメントする?ここをクリック!", URI.unescape(user_meal_url(user_name: @monitored.username, date: @meal.created_at.strftime("%Y/%m/%d"))) %>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

devise_for :users

authenticate :user, lambda { |u| u.is_admin? } do
authenticate :user, ->(u) { u.is_admin? } do
mount RailsAdmin::Engine => "/admin", as: "rails_admin"
mount Sidekiq::Web => "/sidekiq"
end
Expand Down
6 changes: 6 additions & 0 deletions config/sidekiq.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:concurrency: 25
:pidfile: ./tmp/pids/sidekiq.pid
:logfile: ./log/sidekiq.log
:queues:
- default
- mailers
2 changes: 1 addition & 1 deletion spec/jobs/guess_food_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"

RSpec.describe GuessFoodJob, type: :job do
pending "add some examples to (or delete) #{__FILE__}"
Expand Down
3 changes: 3 additions & 0 deletions spec/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
class UserMailerPreview < ActionMailer::Preview
end
5 changes: 5 additions & 0 deletions spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "rails_helper"

RSpec.describe UserMailer, type: :mailer do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 124ea1c

Please sign in to comment.