Created ID5-6-7
-
-
Toggle commit list
-
-
-
Thêm thư mục
public/uploadsvào trong.gitignoreVì thư mục này chứa những dữ liệu của user, không đưa lên source control.
-
Master
dạ ok a
-
app/controllers/job_applieds_controller.rb 0 → 100644
3 before_action :find_job_id, only: [:new] 4 5 def new 6 founded_application = JobApplied.where(user_id: current_user.id, job_id: params[:job_id]) 7 return redirect_to job_detail_path(params[:job_id]) if founded_application.present? 8 end 9 10 def show 11 @jobs = Job.applied_job(current_user.id).page(params[:page]).per(Job::LIMIT_PAGE) 12 end 13 14 def confirmation 15 @founded_job = JobApplied.where(user_id: current_user.id, job_id: apply_params[:job_id]) 16 return redirect_to apply_job_path(job_id: apply_params[:job_id]), flash: {danger: Settings.user.applied_job.applied} if @founded_job.present? 17 18 @user = current_user.job_applieds.new(apply_params) -
Tên biến này không chính xác
current_user.job_applieds.new(apply_params)trả về object làJobApplied=> tên biến phù hợp hơn là
@job_applied -
-
-
app/controllers/job_applieds_controller.rb 0 → 100644
1 class JobAppliedsController < ApplicationController 2 before_action :sign_in_validation, only: [:new, :confirmation, :create, :show] 3 before_action :find_job_id, only: [:new] 4 5 def new 6 founded_application = JobApplied.where(user_id: current_user.id, job_id: params[:job_id]) 7 return redirect_to job_detail_path(params[:job_id]) if founded_application.present? 8 end 9 10 def show 11 @jobs = Job.applied_job(current_user.id).page(params[:page]).per(Job::LIMIT_PAGE) 12 end 13 14 def confirmation 15 @founded_job = JobApplied.where(user_id: current_user.id, job_id: apply_params[:job_id]) -
Edited
@founded_job=>@founded_jobsVì sử dụng
#wherenên trả về sẽ là một mảng các giá trịMục đích là kiểm tra xem record có tồn tại không có thể dùng
#exists?current_user.job_applieds.exists?(job_id: 1) SELECT 1 AS one FROM `job_applieds` WHERE `job_applieds`.`user_id` = 1 AND `job_applieds`.`job_id` = 1 LIMIT 1 -
Master
dạ a, e thử dùng
-
-
-
-
-
app/controllers/job_applieds_controller.rb 0 → 100644
1 class JobAppliedsController < ApplicationController -
JobAppliedsController=>AppliedJobsController -
-
-
app/views/job_applieds/confirmation.html.erb 0 → 100644
1 <div class="container"> 2 <div class="row ribbon-mark"> 3 <%= render partial: 'ribbon_step', locals: { step1: 'active', step2: 'active', step3: '' } %> 4 </div> 5 <h1 class="text-center my-page-label">Confirmation</h1> 6 <div class="form-login"> 7 <div class="row form d-flex justify-content-center"> 8 <%= form_for(@user, url: finished_apply_path) do |f| %> 9 <div class="email-field"> 10 <div class="col-4-sm"> 11 <%= f.label :email %> 12 </div> 13 <div class="col-8-sm"> 14 <strong><%= @user.email %></strong> 15 <%= f.hidden_field :email, value: @user.email %> -
Sử dụng hidden field để lưu trữ những giá trị đã nhập user có thể làm sai lệch dữ liệu
User có thể thay đổi giá trị trong field này khi submit lên server
Tham khảo: https://www.dummies.com/programming/networking/hidden-field-manipulation-hacks-in-web-applications/
-
Master
dạ tks a
-
-
-
app/controllers/job_applieds_controller.rb 0 → 100644
17 18 @user = current_user.job_applieds.new(apply_params) 19 @user.cv_user = current_user.cv_user if apply_params[:cv_user].blank? 20 21 if @user.invalid? 22 flash[:danger] = @user.errors.full_messages.join('<br>') 23 redirect_to apply_job_path(job_id: apply_params[:job_id]) 24 end 25 end 26 27 def create 28 @job = Job.find_by(id: apply_params[:job_id]) 29 @user = current_user.job_applieds.new(apply_params) 30 @user.cv_user.retrieve_from_cache!(apply_params[:cv_user]) 31 if @user.save 32 JobAppliedMailer.apply_job(@user, @job).deliver_later -
Sử dụng
#deliver_latercó tác dụng gì so với#deliver_now? -
Master
e thấy sự dụng deliver_now thì nó trả về lỗi ngắn hơn còn deliver_later dài hơn a. Hiện tại thì e biết như v.
-
-
-
app/controllers/job_applieds_controller.rb 0 → 100644
17 18 @user = current_user.job_applieds.new(apply_params) 19 @user.cv_user = current_user.cv_user if apply_params[:cv_user].blank? 20 21 if @user.invalid? 22 flash[:danger] = @user.errors.full_messages.join('<br>') 23 redirect_to apply_job_path(job_id: apply_params[:job_id]) 24 end 25 end 26 27 def create 28 @job = Job.find_by(id: apply_params[:job_id]) 29 @user = current_user.job_applieds.new(apply_params) 30 @user.cv_user.retrieve_from_cache!(apply_params[:cv_user]) 31 if @user.save 32 JobAppliedMailer.apply_job(@user, @job).deliver_later -
Sử dụng
#deliver_latercó tác dụng gì so với#deliver_now? -
-
-
app/controllers/job_applieds_controller.rb 0 → 100644
18 @user = current_user.job_applieds.new(apply_params) 19 @user.cv_user = current_user.cv_user if apply_params[:cv_user].blank? 20 21 if @user.invalid? 22 flash[:danger] = @user.errors.full_messages.join('<br>') 23 redirect_to apply_job_path(job_id: apply_params[:job_id]) 24 end 25 end 26 27 def create 28 @job = Job.find_by(id: apply_params[:job_id]) 29 @user = current_user.job_applieds.new(apply_params) 30 @user.cv_user.retrieve_from_cache!(apply_params[:cv_user]) 31 if @user.save 32 JobAppliedMailer.apply_job(@user, @job).deliver_later 33 JobAppliedMailer.apply_job(ENV['GMAIL_USERNAME']).deliver_later -
Dòng trên có hoạt động không ?
ENV['GMAIL_USERNAME']hình như trả về một stringJobAppliedMailer.apply_jobyêu cầu 2 tham số là user và job -
Master
chỗ đó bị lỗi a, e thiếu biến @job :d
-
Master
dòng này hiện ko hoạt động a, e đang fix lại
-
-
-
-
-
-
Toggle commit list
-
app/controllers/job_applieds_controller.rb 0 → 100644
2 before_action :sign_in_validation, only: %i[new confirmation create show] 3 before_action :find_job_id, only: [:new] 4 5 def new 6 session[:job_id] = params[:job_id] 7 if session[:job_applied].present? 8 user_name = session[:job_applied]['name'] 9 user_email = session[:job_applied]['email'] 10 end 11 12 session[:job_id] ||= session[:get_job_id] 13 user_name ||= current_user.name 14 user_email ||= current_user.email 15 16 founded_application = JobApplied.exists?(user_id: current_user.id, job_id: session[:job_id]) 17 return redirect_to job_detail_path(session[:job_id]) if founded_application -
Nên thêm thông báo lỗi cho user ở phần này
-
Master
dạ ok a v. để e thêm thông báo
-
-
-
-
Edited by Hoang Phuc Do
1. Ở Apply Form, chưa validate các loại file sẽ được tải lên
Dữ liệu từ user nên được validate đầy đủ để tăng cường bảo mật trên website, trong trường hợp này, user có thể tải lên các đoạn script mã đọc lên server
2. Ở Confirmation, khi nhấn Edit thì quay lại trang Apply Form, mất file đã upload
File mà user đã upload lúc trước phải được hiển thị thay vì phải upload lại file mới
3. Sau khi hoàn thành Apply, nhấn back của Browser lại Apply Form, vẫn có thể điền lại thông tin
Việc này có thể tạo nhiều apply cho cùng job đối với 1 user
-
app/controllers/job_applieds_controller.rb 0 → 100644
31 32 @job_applied.cv_user = current_user.cv_user if apply_params[:cv_user].blank? 33 @job_applied.job_id = session[:get_job_id] if @job_applied.job_id.blank? 34 35 if @job_applied.invalid? 36 flash.now[:danger] = @job_applied.errors.full_messages.join('<br>') 37 render :new 38 end 39 end 40 41 def create 42 @job = Job.find_by(id: session[:get_job_id]) 43 @job_applied = current_user.job_applieds.new(apply_params) 44 @job_applied.job_id = session[:get_job_id] if @job_applied.job_id.blank? 45 @job_applied.cv_user.retrieve_from_cache!(apply_params[:cv_user]) 46 if @job_applied.save -
Master
dạ để e thêm else redirect về trang apply
-
-
app/controllers/job_applieds_controller.rb 0 → 100644
9 user_email = session[:job_applied]['email'] 10 end 11 12 session[:job_id] ||= session[:get_job_id] 13 user_name ||= current_user.name 14 user_email ||= current_user.email 15 16 founded_application = JobApplied.exists?(user_id: current_user.id, job_id: session[:job_id]) 17 return redirect_to job_detail_path(session[:job_id]), flash: {info: 'You applied for job'} if founded_application 18 19 @job_applied = current_user.job_applieds.new(name: user_name, 20 email: user_email) 21 end 22 23 def show 24 @users = current_user.job_applieds.order("job_applieds.updated_at DESC").page(params[:page]).per(Job::LIMIT_PAGE) -
-
app/controllers/job_applieds_controller.rb 0 → 100644
13 user_name ||= current_user.name 14 user_email ||= current_user.email 15 16 founded_application = JobApplied.exists?(user_id: current_user.id, job_id: session[:job_id]) 17 return redirect_to job_detail_path(session[:job_id]), flash: {info: 'You applied for job'} if founded_application 18 19 @job_applied = current_user.job_applieds.new(name: user_name, 20 email: user_email) 21 end 22 23 def show 24 @users = current_user.job_applieds.order("job_applieds.updated_at DESC").page(params[:page]).per(Job::LIMIT_PAGE) 25 end 26 27 def confirmation 28 session[:get_job_id] = session[:job_id] -
Tại sao phải gán hai session cho job id ?
-
Master
phần này e đang sửa lại code gán 1 lần a ơi
-
-
-
-
-
-
27 27 end 28 28 29 29 def show 30 redirect_to jobs_path unless @job 30 session.delete(:apply_job) 31 session.delete(:cv) 32 return redirect_to jobs_path unless @job 33 @user = JobApplied.where(user_id: current_user.id, job_id: params[:id]) if signed_in? -
-
-
-
-
merged
Toggle commit list