Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ end
gem "dotenv-rails", groups: [ :development, :test ]
gem "image_processing", "~> 1.2"
gem "kaminari"

# Sendgrid for email delivery
gem "sendgrid-ruby"
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ GEM
ruby-vips (2.2.3)
ffi (~> 1.12)
logger
ruby_http_client (3.5.5)
rubyzip (2.4.1)
securerandom (0.4.1)
selenium-webdriver (4.32.0)
Expand All @@ -325,6 +326,8 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sendgrid-ruby (6.7.0)
ruby_http_client (~> 3.4)
shoulda-matchers (6.5.0)
activesupport (>= 5.2.0)
sprockets (4.2.2)
Expand Down Expand Up @@ -395,6 +398,7 @@ DEPENDENCIES
rspec-rails
rubocop-rails-omakase
selenium-webdriver
sendgrid-ruby
shoulda-matchers
sprockets-rails
stimulus-rails
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/feedback_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class FeedbackMailer < ApplicationMailer
default from: "noreply@blogspot.com"
default from: "archejewelkim@gmail.com"

def send_feedback(feedback)
@feedback = feedback
Expand Down
7 changes: 7 additions & 0 deletions app/models/feedback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Feedback < ApplicationRecord
validates :name, presence: true
validates :email, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP }
validates :message, presence: true, length: { minimum: 5 }
validate :author_cannot_submit_feedback_on_own_post

after_create :send_feedback_email

Expand All @@ -17,4 +18,10 @@ def send_feedback_email
Rails.logger.error "Failed to send feedback email: #{e.message}"
end
end

def author_cannot_submit_feedback_on_own_post
if blog_post&.author_email&.downcase == email&.downcase
errors.add(:email, "Authors cannot leave feedback on their own posts")
end
end
end
2 changes: 1 addition & 1 deletion app/views/feedback_mailer/send_feedback.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<p><%= simple_format(@feedback.message) %></p>
</div>

<p>Thank you for using Blog Spot!</p>
<p>Thank you for using Blog Post!</p>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion app/views/feedback_mailer/send_feedback.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ From: <%= @feedback.name %> (<%= @feedback.email %>)
Message:
<%= @feedback.message %>

Thank you for using Blog Spot!
Thank you for using Blog Post!
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Blog Spot</title>
<title>Blog Post</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
Expand All @@ -13,7 +13,7 @@
<body class="bg-gray-50 min-h-screen">
<nav class="bg-white shadow-sm border-b">
<div class="max-w-6xl mx-auto px-4 py-4">
<%= link_to "Blog Spot", root_path, class: "text-2xl font-bold text-blue-600 hover:text-blue-800" %>
<%= link_to "Blog Post", root_path, class: "text-2xl font-bold text-blue-600 hover:text-blue-800" %>
<div class="float-right">
<%= link_to "New Post", new_blog_post_path, class: "bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition-colors" %>
</div>
Expand Down
24 changes: 20 additions & 4 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,30 @@
# Raise error when a before_action's only/except options reference missing actions.
config.action_controller.raise_on_missing_callback_actions = true

# for mailer config
config.action_mailer.delivery_method = :letter_opener
# SendGrid SMTP settings for real email delivery in development
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
user_name: "apikey",
password: ENV["SENDGRID_API_KEY"],
domain: "localhost:3000",
address: "smtp.sendgrid.net",
port: 587,
authentication: :plain,
enable_starttls_auto: true
}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { host: "localhost", port: 3000 }

# PREVIOUS SETUP: Letter Opener for email previews in development
# config.action_mailer.delivery_method = :letter_opener
# config.action_mailer.perform_deliveries = true
# config.action_mailer.raise_delivery_errors = true
# config.action_mailer.default_url_options = { host: "localhost", port: 3000 }

# enable letter_opener for development
config.action_mailer.perform_caching = false
# config.action_mailer.perform_caching = false

config.assets.css_compressor = nil

# Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
# config.generators.apply_rubocop_autocorrect_after_generate!
Expand Down
Loading