Commit f5664c95 by Quang Vinh Nguyen

basic job apply

parent 76355015
...@@ -37,13 +37,14 @@ class EntriesController < ApplicationController ...@@ -37,13 +37,14 @@ class EntriesController < ApplicationController
@entry.user_id = @user.id @entry.user_id = @user.id
@entry.job_id = @job.id @entry.job_id = @job.id
respond_to do |format| if @user.jobs.include?(@job)
redirect_to job_url(@job), notice: 'You has been entry this job.'
elsif
if @entry.save if @entry.save
format.html { redirect_to @entry, notice: 'Entry was successfully created.' } UserMailer.job_apply(@user, @job).deliver_now
format.json { render :show, status: :created, location: @entry } redirect_to @entry, notice: 'Email sent to you, Thank you for apply.'
else else
format.html { render :new } render :new
format.json { render json: @entry.errors, status: :unprocessable_entity }
end end
end end
end end
...@@ -51,25 +52,18 @@ class EntriesController < ApplicationController ...@@ -51,25 +52,18 @@ class EntriesController < ApplicationController
# PATCH/PUT /entries/1 # PATCH/PUT /entries/1
# PATCH/PUT /entries/1.json # PATCH/PUT /entries/1.json
def update def update
respond_to do |format|
if @entry.update(entry_params) if @entry.update(entry_params)
format.html { redirect_to @entry, notice: 'Entry was successfully updated.' } redirect_to @entry, notice: 'Entry was successfully updated.'
# format.json { render :show, status: :ok, location: @entry }
else else
format.html { render :edit } render :edit
# format.json { render json: @entry.errors, status: :unprocessable_entity }
end end
end
end end
# DELETE /entries/1 # DELETE /entries/1
# DELETE /entries/1.json # DELETE /entries/1.json
def destroy def destroy
@entry.destroy @entry.destroy
respond_to do |format| redirect_to entries_url, notice: 'Entry was successfully destroyed.'
format.html { redirect_to entries_url, notice: 'Entry was successfully destroyed.' }
format.json { head :no_content }
end
end end
private private
......
class UserMailer < ApplicationMailer
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.user_mailer.job_apply.subject
#
# def job_apply
# @greeting = "Hi"
# mail to: "to@example.org"
# end
def job_apply(user, job)
@user = user
@job = job
mail to: user.email, subject: 'Thank you for apply with VeNJOB'
end
end
...@@ -25,4 +25,9 @@ class User < ApplicationRecord ...@@ -25,4 +25,9 @@ class User < ApplicationRecord
format: { with: VALID_EMAIL_REGEX } format: { with: VALID_EMAIL_REGEX }
validates :password, presence: true, length: { minimum: 8 } validates :password, presence: true, length: { minimum: 8 }
# Sends activation email.
def send_job_apply_email(job)
UserMailer.job_apply(self, job).deliver_now
end
end end
...@@ -21,9 +21,4 @@ ...@@ -21,9 +21,4 @@
<%= form.submit yield(:button_text), class: "btn btn-primary" %> <%= form.submit yield(:button_text), class: "btn btn-primary" %>
<% end %> <% end %>
<% provide(:button_text, 'Save') %> <% provide(:button_text, 'Save') %>
<% @job = Job.find(@entry.job_id) %>
<h1>Editing Entry</h1> <h1>Editing Entry</h1>
<%= render 'form', entry: @entry %> <%= render 'form', entry: @entry %>
......
<% provide(:button_text, 'Apply') %> <% provide(:button_text, 'Apply') %>
<% @job = Job.find(params[:job_id]) %> <% @job = Job.find(params[:job_id]) %>
<h3>Id: <%= @job.id %> -- Job_title: <%= @job.title %> </h3> <h3>Id: <%= @job.id %> -- Job_title: <%= @job.title %> </h3>
<% provide(:job_id, @job.id) %>
<%= render 'form', entry: @entry %> <%= render 'form', entry: @entry %>
\ No newline at end of file
<p id="notice"><%= notice %></p>
<% @job = Job.find(@entry.job_id) %> <% @job = Job.find(@entry.job_id) %>
<h3>Id: <%= @job.id %> -- Job_title: <%= @job.title %> </h3> <h3>Id: <%= @job.id %> -- Job_title: <%= @job.title %> </h3>
...@@ -12,5 +11,5 @@ ...@@ -12,5 +11,5 @@
<%= @entry.entry_email %> <%= @entry.entry_email %>
</p> </p>
<%= link_to 'Edit', edit_entry_path(@entry) %> | <%= link_to 'Edit', edit_entry_path(id: @entry.id) %> |
<%= link_to 'Back', entries_path %> <%= link_to 'Back', entries_path %>
...@@ -13,11 +13,17 @@ ...@@ -13,11 +13,17 @@
</li> </li>
<% if user_signed_in? %> <% if user_signed_in? %>
<li class="nav-item active"> <li class="nav-item active">
<%= link_to 'Logout', destroy_user_session_path, method: :delete %> <%= link_to 'Edit profile', edit_user_registration_path, class: 'nav-link' %>
</li>
<li class="nav-item active">
<%= link_to "Logout", destroy_user_session_path, method: :delete, class: 'nav-link' %>
</li> </li>
<% else %> <% else %>
<li class="nav-item active" > <li class="nav-item active">
<%= link_to 'Login', new_user_session_path %> <%= link_to "Sign up", new_user_registration_path, class: 'nav-link' %>
</li>
<li class="nav-item active">
<%= link_to "Login", new_user_session_path, class: 'nav-link' %>
</li> </li>
<% end %> <% end %>
</ul> </ul>
......
<p>Dear <%= @user.name %></p>
<p>Job title: <%= @job.title %></p>
<p>Location: <%= @job.cities.first.name %></p>
<p>Company: <%= Company.find(@job.company_id).name %></p>
<p>Your submitted information:</p>
<p>Full Name: <%= @user.name %></p>
<p>Email: <%= @user.email %></p>
<p>Best,</p>
<p>Boss</p>
\ No newline at end of file
Dear <%= @user.name %>
Job title: <%= @job.title %>
Location: <%= @job.cities.first.name %>
Company: <%= Company.find(@job.company_id).name %>
Your submitted information:
Full Name: <%= @user.name %>
Email: <%= @user.email %>
Best,
boss
\ No newline at end of file
...@@ -18,8 +18,8 @@ Devise.setup do |config| ...@@ -18,8 +18,8 @@ Devise.setup do |config|
# Configure the e-mail address which will be shown in Devise::Mailer, # Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class # note that it will be overwritten if you use your own mailer class
# with default "from" parameter. # with default "from" parameter.
config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' # config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
config.mailer_sender = 'noreply@example.com'
# Configure the class responsible to send e-mails. # Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer' # config.mailer = 'Devise::Mailer'
......
Rails.application.routes.draw do Rails.application.routes.draw do
root to: 'jobs#home' root to: 'jobs#home'
resources :entries resources :entries
get '/apply', to: 'entries#new' get '/apply', to: 'entries#new'
resources :jobs do resources :jobs do
collection do collection do
get 'home' get 'home'
......
UserMailer#job_apply
Hi, find me in app/views/user_mailer/job_apply
# 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/job_apply
def job_apply
UserMailerMailer.job_apply
end
end
require "rails_helper"
RSpec.describe UserMailer, type: :mailer do
describe "job_apply" do
let(:mail) { UserMailer.job_apply }
it "renders the headers" do
expect(mail.subject).to eq("Job apply")
expect(mail.to).to eq(["to@example.org"])
expect(mail.from).to eq(["from@example.com"])
end
it "renders the body" do
expect(mail.body.encoded).to match("Hi")
end
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