Commit cae46346 by Mai Hoang Thai Ha

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

parent bd849737
...@@ -63,3 +63,4 @@ gem 'slim-rails', '~> 3.2' ...@@ -63,3 +63,4 @@ gem 'slim-rails', '~> 3.2'
gem 'kaminari', :git => 'https://github.com/kaminari/kaminari' gem 'kaminari', :git => 'https://github.com/kaminari/kaminari'
gem 'nokogiri', '~> 1.11', '>= 1.11.7' gem 'nokogiri', '~> 1.11', '>= 1.11.7'
gem 'httparty', '~> 0.18.1' gem 'httparty', '~> 0.18.1'
gem 'active_storage_validations', '~> 0.9.5'
\ No newline at end of file
...@@ -56,6 +56,8 @@ GEM ...@@ -56,6 +56,8 @@ GEM
erubi (~> 1.4) erubi (~> 1.4)
rails-dom-testing (~> 2.0) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_storage_validations (0.9.5)
rails (>= 5.2.0)
activejob (6.1.4) activejob (6.1.4)
activesupport (= 6.1.4) activesupport (= 6.1.4)
globalid (>= 0.3.6) globalid (>= 0.3.6)
...@@ -265,6 +267,7 @@ PLATFORMS ...@@ -265,6 +267,7 @@ PLATFORMS
x86_64-linux x86_64-linux
DEPENDENCIES DEPENDENCIES
active_storage_validations (~> 0.9.5)
bootsnap (>= 1.4.4) bootsnap (>= 1.4.4)
bullet (~> 6.1, >= 6.1.4) bullet (~> 6.1, >= 6.1.4)
byebug byebug
......
...@@ -4,13 +4,14 @@ class AppliesController < ApplicationController ...@@ -4,13 +4,14 @@ class AppliesController < ApplicationController
end end
def create def create
binding.pry @user = User.find_by(id: 1)
@apply = @job.apply_jobs.build(apply_params) @apply = @job.apply_jobs.build(apply_params)
@apply.user_id = 1 @apply.user_id = @user.id
# @apply.cv.attach(params[:apply_job][:cv]) @apply.cv.attach(params[:apply_job][:cv])
if @apply.save 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 else
render 'new' render 'new'
end 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 ...@@ -5,11 +5,12 @@ class ApplyJob < ApplicationRecord
belongs_to :user belongs_to :user
has_one_attached :cv has_one_attached :cv
validates :user_name, presence: true, length: { maximum:50 } validates :user_name, presence: true, length: { maximum: 50 }
validates :email, presence: true, length: { maximum:255 }, validates :email, presence: true, length: { maximum: 255 },
format: {with: VALID_EMAIL_REGEX}, format: { with: VALID_EMAIL_REGEX }
uniqueness: true validates :cv, presence: true,
# validates :image, content_type content_type: { in: %w[application/pdf application/msword application/zip application/xls application/xlsx],
# size: { less_than: 5.megabytes, message: 'must be a valid cv format' },
# message: "should be less than 5MB" } size: { less_than: 5.megabytes,
message: 'should be less than 5MB' }
end end
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
| Confirm | Confirm
= @job.title = @job.title
.col .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 .mb-3
= f.label :name, 'Full name:', class: 'form-label' = f.label :name, 'Full name:', class: 'form-label'
span.mx-2 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 @@ ...@@ -4,7 +4,8 @@
| Apply for | Apply for
= @job.title = @job.title
.col .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 .mb-3
= f.label :user_name, 'Full name', class: 'form-label' = f.label :user_name, 'Full name', class: 'form-label'
= f.text_field :user_name, class: 'form-control' = f.text_field :user_name, class: 'form-control'
......
...@@ -11,6 +11,8 @@ html ...@@ -11,6 +11,8 @@ html
= render 'layouts/shim' = render 'layouts/shim'
body body
= render 'layouts/header' = 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 = yield
= render 'layouts/footer' = 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 ...@@ -81,6 +81,13 @@ Rails.application.configure do
# Bullet.raise = true # raise an error if n+1 query occurs # Bullet.raise = true # raise an error if n+1 query occurs
# Bullet.unused_eager_loading_enable = false # Bullet.unused_eager_loading_enable = false
# end # 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 config.after_initialize do
Bullet.enable = true Bullet.enable = true
Bullet.alert = 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