Skip to content

Commit

Permalink
Merge pull request #12 from nashikotokyo/feature/11_mail_on_activity
Browse files Browse the repository at this point in the history
Feature/11 mail on activity
  • Loading branch information
nashikotokyo committed Apr 29, 2022
2 parents f544606 + fdaa8dc commit 87ec5bb
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -30,4 +30,7 @@
/vendor
dump.rdb
.DS_Store
/public/uploads
/public/uploads
config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -44,6 +44,7 @@ gem 'carrierwave'
gem 'mini_magick'
gem 'font-awesome-sass'
gem 'kaminari'
gem 'config'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand All @@ -64,6 +65,7 @@ group :development do
gem 'binding_of_caller'
gem 'pry-rails'
gem 'pry-byebug'
gem 'letter_opener_web'
end

group :test do
Expand Down
46 changes: 46 additions & 0 deletions Gemfile.lock
Expand Up @@ -86,8 +86,44 @@ GEM
nokogiri (~> 1.8)
coderay (1.1.3)
concurrent-ruby (1.1.9)
config (4.0.0)
deep_merge (~> 1.2, >= 1.2.1)
dry-validation (~> 1.0, >= 1.0.0)
crass (1.0.6)
debug_inspector (1.1.0)
deep_merge (1.2.2)
dry-configurable (0.13.0)
concurrent-ruby (~> 1.0)
dry-core (~> 0.6)
dry-container (0.9.0)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.13, >= 0.13.0)
dry-core (0.7.1)
concurrent-ruby (~> 1.0)
dry-inflector (0.2.1)
dry-initializer (3.0.4)
dry-logic (1.2.0)
concurrent-ruby (~> 1.0)
dry-core (~> 0.5, >= 0.5)
dry-schema (1.8.0)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.13, >= 0.13.0)
dry-core (~> 0.5, >= 0.5)
dry-initializer (~> 3.0)
dry-logic (~> 1.0)
dry-types (~> 1.5)
dry-types (1.5.1)
concurrent-ruby (~> 1.0)
dry-container (~> 0.3)
dry-core (~> 0.5, >= 0.5)
dry-inflector (~> 0.1, >= 0.1.2)
dry-logic (~> 1.0, >= 1.0.2)
dry-validation (1.7.0)
concurrent-ruby (~> 1.0)
dry-container (~> 0.7, >= 0.7.1)
dry-core (~> 0.5, >= 0.5)
dry-initializer (~> 3.0)
dry-schema (~> 1.8, >= 1.8.0)
erubi (1.10.0)
execjs (2.8.1)
faker (2.19.0)
Expand Down Expand Up @@ -144,6 +180,14 @@ GEM
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
launchy (2.5.0)
addressable (~> 2.7)
letter_opener (1.8.1)
launchy (>= 2.2, < 3)
letter_opener_web (1.4.1)
actionmailer (>= 3.2)
letter_opener (~> 1.0)
railties (>= 3.2)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand Down Expand Up @@ -336,12 +380,14 @@ DEPENDENCIES
capybara (>= 2.15)
carrierwave
chromedriver-helper
config
faker
font-awesome-sass
html2slim
jbuilder (~> 2.5)
jquery-rails
kaminari
letter_opener_web
listen (>= 3.0.5, < 3.2)
mini_magick
mysql2 (>= 0.4.4, < 0.6.0)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/comments_controller.rb
Expand Up @@ -3,7 +3,7 @@ class CommentsController < ApplicationController

def create
@comment = current_user.comments.build(comment_params)
@comment.save
UserMailer.with(user_from: current_user, user_to: @comment.post.user, comment: @comment).comment_post.deliver_later if @comment.save
end

def edit
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/likes_controller.rb
Expand Up @@ -3,7 +3,7 @@ class LikesController < ApplicationController

def create
@post = Post.find(params[:post_id])
current_user.like(@post)
UserMailer.with(user_from: current_user, user_to: @post.user, post: @post).like_post.deliver_later if current_user.like(@post)
end

def destroy
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/relationships_controller.rb
Expand Up @@ -3,7 +3,7 @@ class RelationshipsController < ApplicationController

def create
@user = User.find(params[:followed_id])
current_user.follow(@user)
UserMailer.with(user_from: current_user, user_to: @user).follow.deliver_later if current_user.follow(@user)
end

def destroy
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
default from: 'instaclone@example.com'
layout 'mailer'
end
21 changes: 21 additions & 0 deletions app/mailers/user_mailer.rb
@@ -0,0 +1,21 @@
class UserMailer < ApplicationMailer
def like_post
@user_from = params[:user_from]
@user_to = params[:user_to]
@post = params[:post]
mail(to: @user_to.email, subject: "#{@user_from.username}があなたの投稿にいいねしました")
end

def comment_post
@user_from = params[:user_from]
@user_to = params[:user_to]
@comment = params[:comment]
mail(to: @user_to.email, subject: "#{@user_from.username}があなたの投稿にコメントしました")
end

def follow
@user_from = params[:user_from]
@user_to = params[:user_to]
mail(to: @user_to.email, subject: "#{@user_from.username}があなたをフォローしました")
end
end
3 changes: 3 additions & 0 deletions app/views/user_mailer/comment_post.html.slim
@@ -0,0 +1,3 @@
h2 = "#{@user_to.username}さん"
p = "#{@user_from.username}さんがあなたの投稿にコメントしました。"
= link_to "確認する", post_url(@comment.post, { anchor: "comment-#{@comment.id}" })
3 changes: 3 additions & 0 deletions app/views/user_mailer/follow.html.slim
@@ -0,0 +1,3 @@
h2 = "#{@user_to.username}さん"
p = "#{@user_from.username}さんがあなたをフォローしました。"
= link_to "確認する", user_url(@user_from)
3 changes: 3 additions & 0 deletions app/views/user_mailer/like_post.html.slim
@@ -0,0 +1,3 @@
h2 = "#{@user_to.username}さん"
p = "#{@user_from.username}さんがあなたの投稿にいいねしました。"
= link_to "確認する", post_url(@post)
3 changes: 3 additions & 0 deletions config/environments/development.rb
Expand Up @@ -60,4 +60,7 @@
config.file_watcher = ActiveSupport::EventedFileUpdateChecker

config.session_store :redis_store, servers: 'redis://localhost:6379/0', expire_after: 1.day

config.action_mailer.default_url_options = Settings.default_url_options.to_h
config.action_mailer.delivery_method = :letter_opener_web
end
58 changes: 58 additions & 0 deletions config/initializers/config.rb
@@ -0,0 +1,58 @@
Config.setup do |config|
# Name of the constant exposing loaded settings
config.const_name = 'Settings'

# Ability to remove elements of the array set in earlier loaded settings file. For example value: '--'.
#
# config.knockout_prefix = nil

# Overwrite an existing value when merging a `nil` value.
# When set to `false`, the existing value is retained after merge.
#
# config.merge_nil_values = true

# Overwrite arrays found in previously loaded settings file. When set to `false`, arrays will be merged.
#
# config.overwrite_arrays = true

# Load environment variables from the `ENV` object and override any settings defined in files.
#
# config.use_env = false

# Define ENV variable prefix deciding which variables to load into config.
#
# Reading variables from ENV is case-sensitive. If you define lowercase value below, ensure your ENV variables are
# prefixed in the same way.
#
# When not set it defaults to `config.const_name`.
#
config.env_prefix = 'SETTINGS'

# What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well
# with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where
# using dots in variable names might not be allowed (eg. Bash).
#
# config.env_separator = '.'

# Ability to process variables names:
# * nil - no change
# * :downcase - convert to lower case
#
# config.env_converter = :downcase

# Parse numeric values as integers instead of strings.
#
# config.env_parse_values = true

# Validate presence and type of specific config values. Check https://github.com/dry-rb/dry-validation for details.
#
# config.schema do
# required(:name).filled
# required(:age).maybe(:int?)
# required(:email).filled(format?: EMAIL_REGEX)
# end

# Evaluate ERB in YAML config files at load time.
#
# config.evaluate_erb_in_yaml = true
end
4 changes: 4 additions & 0 deletions config/routes.rb
Expand Up @@ -42,6 +42,10 @@
# rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create

Rails.application.routes.draw do
if Rails.env.development?
mount LetterOpenerWeb::Engine, at: "/letter_opener"
end

root 'posts#index'

get 'login', to: 'user_sessions#new'
Expand Down
Empty file added config/settings.yml
Empty file.
2 changes: 2 additions & 0 deletions config/settings/development.yml
@@ -0,0 +1,2 @@
default_url_options:
host: 'localhost:3000'
Empty file added config/settings/production.yml
Empty file.
Empty file added config/settings/test.yml
Empty file.

0 comments on commit 87ec5bb

Please sign in to comment.