Commit ba345db2 by Thanh Hung Pham

Fix comment - change javascript to remote:true

parent 0226f7a2
$(function() {
$( ".favorite_add" ).on( "click", function() {
$.ajax({
url: "/jobs/favorite",
type: "GET",
data: {"job_id" : $("#job_id").val()},
dataType: "json",
success: function(data) {
window.location.reload();
}
});
});
// $( ".favorite_add" ).on( "click", function() {
// $.ajax({
// url: "/jobs/favorite",
// type: "GET",
// data: {"job_id" : $("#job_id").val()},
// dataType: "json",
// success: function(data) {
// window.location.reload();
// }
// });
// });
$(".favorite_remove").on("click", function() {
$.ajax({
......
......@@ -51,12 +51,14 @@ class JobsController < ApplicationController
end
def favorite
job = Job.find(params[:job_id])
@job_id = params[:job_id]
job = Job.find(@job_id)
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])
@job_id = params[:job_id]
job = Job.find(@job_id)
Favorite.where(user: current_user, job: job).destroy_all
end
......
$("#favorite_<%= @job_id %>").remove()
$("#favorite_remove_<%= @job_id %>").remove()
......@@ -12,13 +12,13 @@
</thead>
<tbody>
<%- @favorited_jobs.each do |favorite| -%>
<tr>
<tr id="favorite_remove_<%= favorite.job.id %>">
<td> <%= link_to favorite.job.name, job_path(favorite.job.id) %> </td>
<td> <%= truncate(favorite.job.description, length: 250) %> </td>
<td> <%= favorite.job.city.try(:name) %> </td>
<td> <%= favorite.job.salary %> </td>
<td>
<%= link_to 'Remove', '#', class: 'favorite_remove' %>
<%= link_to 'Remove', jobs_favorite_remove_path(job_id: favorite.job.id, format: 'js'), remote: true, class: 'favorite_remove' %>
<input type="hidden" id="job_id" name="job_id" value="<%= favorite.job.id %>">
</td>
</tr>
......
......@@ -35,9 +35,9 @@
<td> <%= job.salary %> </td>
<td>
<%- if Favorite.where(user: current_user, job: job).blank? -%>
<div class="col-md-3">
<div class="col-md-3" id="favorite_<%= job.id %>">
<%- if user_signed_in? -%>
<%= link_to 'Favorite', '#', class: 'favorite_add' %>
<%= link_to 'Favorite', jobs_favorite_path(job_id: job.id, format: 'js'), remote: true, class: 'favorite_add' %>
<%- else -%>
<%= link_to 'Favorite', new_user_session_path %>
<%- 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