Commit 07db8223 by Hoang Phuc

Apply, Favorite job, add columns to tbl_user

parent 627b4293
Pipeline #574 failed with stages
in 0 seconds
...@@ -10,20 +10,26 @@ ...@@ -10,20 +10,26 @@
$(".back2top").click(function(){ $(".back2top").click(function(){
$("html, body").animate({scrollTop: 0}, 500); $("html, body").animate({scrollTop: 0}, 500);
}) })
$(".job_application .application_button").click(function (e) { $(".apply-or-favorite-jobs").click(function (e) {
e.preventDefault() e.preventDefault()
data = { job_ids: [$(this).data("id")] } data = {
job_ids: [$(this).data("id")],
type: $(this).data("type")
}
$.ajax({ $.ajax({
url: '/job/apply', url: '/apply_or_favorite',
data: data, data: data,
type: 'POST', type: 'POST',
success: (res) => { success: (res) => {
console.log("response: ", res) alert(res.message)
}, },
error: (err) => { error: (err) => {
console.log("error: ", err) if(err.status === 401){
if(confirm(err.responseJSON.message)){
window.location.href = "/users/sign_in";
}
}
} }
}); });
}) })
})(jQuery); })(jQuery);
\ No newline at end of file
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:full_name])
devise_parameter_sanitizer.permit(:account_update, keys: [:full_name, :cv])
end
end end
...@@ -35,7 +35,26 @@ class JobsController < ApplicationController ...@@ -35,7 +35,26 @@ class JobsController < ApplicationController
@title = "Job was not found" @title = "Job was not found"
end end
end end
def apply_jobs def apply_or_favorite_jobs
unless current_user
payload = {
message: "You are not logged in, please login to operate the feature",
}
render :json => payload, :status => :unauthorized
else
if params[:job_ids].present?
params[:job_ids].each do |id|
if params[:type] == "apply"
Apply.find_or_create_by({:user_id => current_user.id, :job_id => id})
else
Favorite.find_or_create_by({:user_id => current_user.id, :job_id => id})
end
end
payload = {
message: "Thank you for #{params[:type] == "apply" ? "applied" : "favourited"} with VenJob",
}
render :json => payload, :status => :ok
end
end
end end
end end
...@@ -10,8 +10,13 @@ ...@@ -10,8 +10,13 @@
<%= render "devise/shared/error_messages", resource: resource %> <%= render "devise/shared/error_messages", resource: resource %>
<p class="field"> <p class="field">
<%= f.label :full_name %><br />
<%= f.text_field :full_name, autofocus: true, autocomplete: "full_name" %>
</p>
<p class="field">
<%= f.label :email %><br /> <%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email" %> <%= f.email_field :email, autocomplete: "email" %>
</p> </p>
<p class="field"> <p class="field">
......
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
</aside> </aside>
<aside class="widget widget--job_listing"> <aside class="widget widget--job_listing">
<div class="job_application application"> <div class="job_application application">
<input type="button" class="application_button button" value="Apply for job" /> <input type="button" class="application_button button apply-or-favorite-jobs" value="Apply for job" data-id="<%= @job.id %>" data-type="apply"/>
</div> </div>
<div class="job-manager-form wp-job-manager-bookmarks-form"> <div class="job_application application">
<a class="bookmark-notice" href="https://jobify-demos.astoundify.com/classic/account/">Favorite</a> <input type="button" class="application_button favorite-button button apply-or-favorite-jobs" value="Favorite" data-id="<%= @job.id %>" data-type="favorite"/>
</div> </div>
</aside> </aside>
<aside class="widget widget--job_listing"> <aside class="widget widget--job_listing">
......
...@@ -49,6 +49,9 @@ ...@@ -49,6 +49,9 @@
<a href="/history">History</a> <a href="/history">History</a>
</li> </li>
<% if current_user %> <% if current_user %>
<li class="register menu-item menu-item-type-post_type menu-item-object-page menu-item-99991219">
<%= link_to 'Hi, ' + current_user.full_name, edit_user_registration_path %>
</li>
<li class="login menu-item menu-item-type-post_type menu-item-object-page menu-item-99991213"> <li class="login menu-item menu-item-type-post_type menu-item-object-page menu-item-99991213">
<%= link_to 'Sign out', destroy_user_session_path, method: :delete %> <%= link_to 'Sign out', destroy_user_session_path, method: :delete %>
</li> </li>
......
...@@ -12,5 +12,5 @@ Rails.application.routes.draw do ...@@ -12,5 +12,5 @@ Rails.application.routes.draw do
get '/industries/', to: 'industries#index', as: 'industries' get '/industries/', to: 'industries#index', as: 'industries'
get '/history/', to: 'history#index' get '/history/', to: 'history#index'
post 'job/apply', to: 'job#apply_jobs' post 'apply_or_favorite', to: 'jobs#apply_or_favorite_jobs'
end end
class AddColumnsToUsers < ActiveRecord::Migration[6.0]
def change
add_column :users, :full_name, :string
add_column :users, :cv, :string
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_04_08_025325) do ActiveRecord::Schema.define(version: 2020_04_10_070154) do
create_table "applies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "applies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "user_id", null: false t.bigint "user_id", null: false
...@@ -87,6 +87,8 @@ ActiveRecord::Schema.define(version: 2020_04_08_025325) do ...@@ -87,6 +87,8 @@ ActiveRecord::Schema.define(version: 2020_04_08_025325) do
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.string "full_name"
t.string "cv"
t.index ["email"], name: "index_users_on_email", unique: true t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
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