Commit cae46346 by Mai Hoang Thai Ha

create form: apply, confirm, done; add validates gem; install and add mailler

parent bd849737
......@@ -62,4 +62,5 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'slim-rails', '~> 3.2'
gem 'kaminari', :git => 'https://github.com/kaminari/kaminari'
gem 'nokogiri', '~> 1.11', '>= 1.11.7'
gem 'httparty', '~> 0.18.1'
\ No newline at end of file
gem 'httparty', '~> 0.18.1'
gem 'active_storage_validations', '~> 0.9.5'
\ No newline at end of file
......@@ -56,6 +56,8 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_storage_validations (0.9.5)
rails (>= 5.2.0)
activejob (6.1.4)
activesupport (= 6.1.4)
globalid (>= 0.3.6)
......@@ -265,6 +267,7 @@ PLATFORMS
x86_64-linux
DEPENDENCIES
active_storage_validations (~> 0.9.5)
bootsnap (>= 1.4.4)
bullet (~> 6.1, >= 6.1.4)
byebug
......
......@@ -4,13 +4,14 @@ class AppliesController < ApplicationController
end
def create
binding.pry
@user = User.find_by(id: 1)
@apply = @job.apply_jobs.build(apply_params)
@apply.user_id = 1
# @apply.cv.attach(params[:apply_job][:cv])
@apply.user_id = @user.id
@apply.cv.attach(params[:apply_job][:cv])
if @apply.save
#afasf
UserMailer.apply_job(@user, @job, @apply).deliver_now
flash.now[:info] = 'Job application information has been sent to your email'
else
render 'new'
end
......
class UserMailer < ApplicationMailer
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.user_mailer.apply_job.subject
#
def apply_job(user, job, apply)
@user = user
@job = job
@apply = apply
mail to: user.email, subject: 'aplly job'
end
end
......@@ -5,11 +5,12 @@ class ApplyJob < ApplicationRecord
belongs_to :user
has_one_attached :cv
validates :user_name, presence: true, length: { maximum:50 }
validates :email, presence: true, length: { maximum:255 },
format: {with: VALID_EMAIL_REGEX},
uniqueness: true
# validates :image, content_type
# size: { less_than: 5.megabytes,
# message: "should be less than 5MB" }
validates :user_name, presence: true, length: { maximum: 50 }
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX }
validates :cv, presence: true,
content_type: { in: %w[application/pdf application/msword application/zip application/xls application/xlsx],
message: 'must be a valid cv format' },
size: { less_than: 5.megabytes,
message: 'should be less than 5MB' }
end
......@@ -4,7 +4,8 @@
| Confirm
= @job.title
.col
= form_with(scope: :apply_job, url: done_path(job_id: @job), local: true) do |f|
= form_with(model: @apply, scope: :apply_job, url: done_path(job_id: @job), local: true) do |f|
.mb-3
= f.label :name, 'Full name:', class: 'form-label'
span.mx-2
......
.container.text-center
h3.my-4
| You have successfully applied for the #{@job.title}
p Good luck! Thank you for using our service
= link_to 'Keep looking for another job', root_path
......@@ -4,7 +4,8 @@
| Apply for
= @job.title
.col
= form_with(model: @apply, url: confirm_path(job_id: @job), local: true) do |f|
= form_with(model: @apply, scope: :apply_job, url: confirm_path(job_id: @job), local: true) do |f|
= render 'shared/error_messages', object: f.object
.mb-3
= f.label :user_name, 'Full name', class: 'form-label'
= f.text_field :user_name, class: 'form-control'
......
......@@ -11,6 +11,8 @@ html
= render 'layouts/shim'
body
= render 'layouts/header'
.container-fluid
.container-fluid style ="min-height:80vh;"
- flash.each do |message_type, message|
div class=("text-center alert alert-#{message_type}") = message
= yield
= render 'layouts/footer'
\ No newline at end of file
= render 'layouts/footer'
\ No newline at end of file
- if object.errors.any?
#error_explanation.bg_danger
.alert.alert-danger
| The form contains
= pluralize(object.errors.count, "error")
ul.mb-3
- object.errors.full_messages.each do |msg|
li.text-danger
= msg
\ No newline at end of file
h1 VenJob
p
| Dear #{@user.name},
p Thank you for applied with VenJOB. Your applied job's information is as follow:
p
| Job title: #{@job.title}
p
| Location:
- @job.cities.each do |city|
span= city.name
p
| Company: #{@job.company.name}
br/
p Your submitted information:
p
| Full name: #{@apply.user_name}
p
| Email: #{@apply.email}
p CV:
p Best,
' VenJob
= "\r\n" * 2
' Dear #{@user.name},
= "\n"
' Thank you for applied with VenJOB. Your applied job's information is as follow:
= "\n"
' Job title: #{@job.title}
= "\n"
' Company: #{@job.company.name}
= "\n"
' Your submitted information:
= "\n"
' Full name: #{@apply.user_name}
= "\n"
' Email: #{@apply.email}
= "\n"
' CV: #{@apply.cv}
= "\n"
' Best,
......@@ -81,6 +81,13 @@ Rails.application.configure do
# Bullet.raise = true # raise an error if n+1 query occurs
# Bullet.unused_eager_loading_enable = false
# end
config.action_mailer.raise_delivery_errors = false
host = 'localhost:3000' # Local
# config.action_mailer.default_url_options = { host: host, protocol: 'https' }
# Use this if developing on localhost.
config.action_mailer.default_url_options = { host: host, protocol: 'http' }
config.after_initialize do
Bullet.enable = true
Bullet.alert = true
......
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
class UserMailerPreview < ActionMailer::Preview
# Preview this email at http://localhost:3000/rails/mailers/user_mailer/apply_job
def apply_job
UserMailer.apply_job
end
end
require "test_helper"
class UserMailerTest < ActionMailer::TestCase
test "apply_job" do
mail = UserMailer.apply_job
assert_equal "Apply job", mail.subject
assert_equal ["to@example.org"], mail.to
assert_equal ["from@example.com"], mail.from
assert_match "Hi", mail.body.encoded
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment