Commit 068e93ee by Thanh Hung Pham

Show favorite page

parent ba20bcd6
......@@ -11,7 +11,6 @@
// about supported directives.
//
//= require rails-ujs
//= require turbolinks
//= require jquery
//= require jquery_ujs
//= require_tree .
......
$(function() {
$(".favorite_add").click(function(event){
$( ".favorite_add" ).on( "click", function() {
$.ajax({
url: "/jobs/favorite",
type: "POST",
data: {"job_id" : $("#job_id").val()},
dataType: "json",
success: function(data) {
window.location.reload();
}
});
});
$(".favorite_remove").on("click", function() {
$.ajax({
url: "/jobs/favorite_remove",
type: "POST",
data: {"job_id" : $("#job_id").val()},
dataType: "json",
success: function(data) {
window.location.reload();
}
});
});
......
......@@ -24,6 +24,11 @@ class JobsController < ApplicationController
Favorite.new(user: current_user, job: job).save if Favorite.where(user: current_user, job: job).blank?
end
def favorite_remove
job = Job.find(params[:job_id])
Favorite.where(user: current_user, job: job).destroy
end
def favorited_jobs
@favorited_jobs = Favorite.where(user: current_user)
end
......
......@@ -18,7 +18,9 @@
</div>
<div class="col-md-4">
<%= link_to 'Remove', '#', class: 'favorite_remove' %>
<input type="hidden" id="job_id" name="job_id" value="<%= favorite.job.id %>">
</div>
</div>
<%- end -%>
</div>
......@@ -9,6 +9,8 @@ Rails.application.routes.draw do
get 'jobs/show/', to: 'jobs#show'
get 'jobs/favorite', to: 'jobs#favorite'
post 'jobs/favorite', to: 'jobs#favorite'
get 'jobs/favorite_remove', to: 'jobs#favorite_remove'
post 'jobs/favorite_remove', to: 'jobs#favorite_remove'
get 'jobs/favorited_jobs', to: 'jobs#favorited_jobs'
get 'jobs/history_jobs', to: 'jobs#history_jobs'
......
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