Commit 068e93ee by Thanh Hung Pham

Show favorite page

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