Commit 52e930fe by Thanh Hung Pham

Add favorite feature

parent c6aba513
......@@ -21,6 +21,7 @@ gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
......
......@@ -91,6 +91,10 @@ GEM
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
jquery-rails (4.3.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
......@@ -210,6 +214,7 @@ DEPENDENCIES
devise
figaro
jbuilder (~> 2.5)
jquery-rails
listen (>= 3.0.5, < 3.2)
mysql2 (>= 0.3.18, < 0.5)
puma (~> 3.7)
......
......@@ -12,5 +12,7 @@
//
//= require rails-ujs
//= require turbolinks
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require bootstrap
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
$(function() {
$(".favorite_add").click(function(event){
$.ajax({
url: "/jobs/favorite",
type: "POST",
data: {"job_id" : $("#job_id").val()},
dataType: "json",
success: function(data) {
}
});
});
});
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
......@@ -20,10 +20,7 @@ class JobsController < ApplicationController
end
def favorite
if user_signed_in?
else
redirect_to new_user_session_path
end
job = Job.find(params[:job_id])
Favorite.new(user: current_user, job: job).save if Favorite.where(user: current_user, job: job).blank?
end
end
......@@ -28,9 +28,16 @@
<%= job.city.name unless job.city.nil? %>
<%= job.salary %>
</div>
<div class="col-md-3">
<%= link_to 'Favorite', jobs_favorite_path(job_id: job.id) %>
</div>
<%- if Favorite.where(user: current_user, job: job).blank? -%>
<div class="col-md-3">
<%- if user_signed_in? -%>
<%= link_to 'Favorite', '#', class: 'favorite_add' %>
<%- else -%>
<%= link_to 'Favorite', new_user_session_path %>
<%- end -%>
<input type="hidden" id="job_id" name="job_id" value="<%= job.id %>">
</div>
<%- end -%>
</div>
<%- end -%>
......
......@@ -8,6 +8,7 @@ Rails.application.routes.draw do
get 'jobs/applied_jobs', to: 'jobs#applied_jobs'
get 'jobs/show/', to: 'jobs#show'
get 'jobs/favorite', to: 'jobs#favorite'
post 'jobs/favorite', to: 'jobs#favorite'
resource :cities
devise_scope :user do
......
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