Commit b67616df by Hoang Nam Nguyen

'create job_list_favorite'

parent 4c4659ae
class FavoriteController < ApplicationController class FavoriteController < ApplicationController
before_action :logged_in? before_action :logged_in?, only: [:create, :destroy]
def create def create
binding.pry @job_id = Job.find(params[:favorite_job][:job_id]).id
@job = Job.find(params[:favorite_job]) current_user.favorite!(@job_id)
current_user.favorite!(@job)
end end
def destroy def destroy
@job = Favorite.find(params[:id]).job @job_id =Job.find(params[:destroy_favorite_job][:job_id]).id
current_user.unfavorite!(@job) current_user.unfavorite!(@job_id)
end end
# private def favorite_list
@user = current_user
# def set_job_id @jobs = ::Kaminari.paginate_array(@user.favorites).page(params[:page]).per(20)
# session[:job] = Job.find(params[:favorite_job][:job_id]) end
# end
end end
...@@ -20,9 +20,6 @@ class TopPagesController < ApplicationController ...@@ -20,9 +20,6 @@ class TopPagesController < ApplicationController
@job = @user.histories.new_list_history(ENV["NUMBER_HISTORY_PAGE"]) @job = @user.histories.new_list_history(ENV["NUMBER_HISTORY_PAGE"])
end end
def favorite_job
end
def index def index
end end
end end
......
...@@ -47,14 +47,12 @@ class UsersController < ApplicationController ...@@ -47,14 +47,12 @@ class UsersController < ApplicationController
def my_jobs def my_jobs
@user = current_user @user = current_user
@job = @user.applies @jobs = ::Kaminari.paginate_array(@user.applies).page(params[:page]).per(20)
@job_pages= ::Kaminari.paginate_array(@user.applies).page(params[:page]).per(20)
end end
def favorite def favorite
@title = 'Favorite Jobs' @title = 'Favorite Jobs'
@job = current_user.jobs.build @job = current_user.jobs.build
@feed_jobs = current_user.favorite_jobs.paginate(page: params[:page])
end end
private private
......
...@@ -58,16 +58,17 @@ class User < ApplicationRecord ...@@ -58,16 +58,17 @@ class User < ApplicationRecord
end end
def favorite?(job) def favorite?(job)
favorites.find_by(job_id: job['job_id']) favorites.find_by(job_id: job['job_id'] || job.id)
end end
def favorite!(job) def favorite!(job_id)
favorites.create!(job_id: job.id) favorites.create!(job_id: job_id)
end end
def unfavorites!(job) def unfavorite!(job_id)
favorites.find_by(job_id: job.id).destroy favorites.find_by(job_id: job_id).destroy
end end
private private
def downcase_email def downcase_email
......
<%= form_for(:favorite_job, url: create_favorite_path, remote: true, method: :post) do |f| %> <%= form_for(:favorite_job, url: create_favorite_path, remote: true, method: :post) do |f| %>
<div><%= f.hidden_field :job_id, value: job['job_id'] %></div> <div><%= f.hidden_field :job_id, value: job_id %></div>
<%= f.submit "Favorite",class: 'fa fa-heartbeat' %> <%= button_tag(type: "submit", class: "btn btn-success btn-block") do %>
<i class="fa fa-heart 4px"></i> Favorite
<% end %>
<% end %> <% end %>
\ No newline at end of file
<%= form_for(:destroy_favorite_job, url: destroy_favorite_path, remote: true, method: :delete) do |f| %>
<%= form_for(current_user.favorites.find_by(job_id: job['job_id']), <div><%= f.hidden_field :job_id, value: job_id %></div>
html: {method: :delete}) do |f| %> <%= button_tag(type: "submit", class: "btn btn-danger btn-block") do %>
<%= f.submit "Unfavorite", class: "btn"%> <i class="fa fa-heartbeat 4px"></i> Unfavorite
<% end %> <% end %>
<% end %>
\ No newline at end of file
<div class="container mt-5" >
<div class="row mb-5 ml-5">
<div class="search_list titlejob col-md-10">
<div class="container">
<div class="row">
<div class="col-1 mt-5">
<%= radio_button_tag 'job_id', favorite.job.id %>
</div>
<div class="col-11" >
<%= link_to favorite.job.job_title,job_detail_path(favorite.job.id),class: 'search_list_jobs_title' %>
<% if favorite.job.short_description.present? %>
<li class="detail_description">
<%= truncate favorite.job.short_description,length: 250 %>
<%= link_to 'read more',job_detail_path(favorite.job.id)%></li>
</li>
<% end %>
<div class="row ml-0">
<li class="detail_description col-md-5">
<%= favorite.job.cities.map(&:location).join(',') %>
</li>
<% if favorite.job.salary.present? %>
<li class=" detail_description float-right text-success col-md-5">
<%= favorite.job.salary%>
</li>
<% end %>
</div>
</div>
<div class="col-md-2 mt-2">
<div id="follow_form_<%= favorite.job.id %>">
<% if current_user.favorite?(favorite.job) %>
<%= render 'favorite/destroy', job_id: favorite.job.id %>
<% end %>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
// $("#favorite_form").html("<%= escape_javascript(render('users/unfavorite')) %>"); $("#follow_form_<%= @job_id %>").html('<%= escape_javascript(render("favorite/destroy", job_id: @job_id)) %>')
// $("#favorites").html('<%= current_.favorites.job.count %>'); $('#followers').text('<%= current_user.favorites.count %>')
$("#follow_form").html('<%= escape_javascript(render("favorites/create", job: @job)) %>')
$('#favorites').text('<%= current_user.favorites.count %>')
\ No newline at end of file
// $("#follow_form").html("<%= escape_javascript(render('favorite/favorite')) %>"); $("#follow_form_<%= @job_id %>").html('<%= escape_javascript(render("favorite/create", job_id: @job_id)) %>')
// $("#favorites").html('<%= current_user.favorites.job.count %>'); $('#followers').text('<%= current_user.favorites.count %>');
$('#follow_form %>').html('<%= escape_javascript(render("favorite/destroy", job: @job)) %>');
$('#favorites').text('<%= current_user.favorites.count %>');
\ No newline at end of file
<%= provide(:title,"Favorite List")%>
<h1 class="text-danger text-center mt-5">Favorite Jobs</h1>
<%= form_tag(form_apply_path, method: :get) do %>
<%= paginate @jobs,theme: 'twitter-bootstrap-4'%>
<%= render partial: "favorite",collection: @jobs, as: :favorite %>
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-9">
<%= button_tag(type: "submit", class: "btn btn-danger btn-block mb-5") do %>
<i class="fa fa-key 4px "></i> Apply
<% end %>
</div>
</div>
<%= paginate @jobs,theme: 'twitter-bootstrap-4'%>
<% end %>
...@@ -22,11 +22,11 @@ ...@@ -22,11 +22,11 @@
</div> </div>
<div class="col-md-2 mt-2"> <div class="col-md-2 mt-2">
<div id="follow_form"> <div id="follow_form_<%= job['job_id'].to_s %>">
<% if current_user.favorite?(job) %> <% if current_user.favorite?(job) %>
<%= render 'favorite/destroy', job: job %> <%= render 'favorite/destroy', job_id: job['job_id'] %>
<% else %> <% else %>
<%= render 'favorite/create', job: job %> <%= render 'favorite/create', job_id: job['job_id'] %>
<% end %> <% end %>
</div> </div>
</div> </div>
......
...@@ -2,10 +2,23 @@ ...@@ -2,10 +2,23 @@
<div class="container mt-5"> <div class="container mt-5">
<div class="text-center"> <div class="text-center">
<%= link_to 'TOP', root_path, { class: 'btn btn-success' } %>
<%= link_to 'CITY',cities_path , { class: 'btn btn-success' } %> <%= link_to root_path, class: 'btn btn-success' do %>
<%= link_to 'INDUSTRY', industries_path, { class: 'btn btn-success' } %> <i class="fa fa-home"></i> TOP
<%= link_to 'SHORT TITLE', '#', { class: 'btn btn-success' } %> <% end %>
<%= link_to cities_path, class: 'btn btn-danger' do %>
<i class="fa fa-location-arrow"></i> CITY
<% end %>
<%= link_to industries_path, class: 'btn btn-primary' do %>
<i class="fa fa-location-arrow"></i> INDUSTRY
<% end %>
<%= link_to '#', class: 'btn btn-warning' do %>
<i class="fa fa-book"></i> SHORT TITLE
<% end %>
<% if logged_in? && current_user.applied_job?(@job) %> <% if logged_in? && current_user.applied_job?(@job) %>
<%= link_to 'Applied',root_path, {class: 'btn btn-primary float-right'} %> <%= link_to 'Applied',root_path, {class: 'btn btn-primary float-right'} %>
<h1 class="text-danger mt-5"> You applied this job </h1> <h1 class="text-danger mt-5"> You applied this job </h1>
...@@ -28,8 +41,26 @@ ...@@ -28,8 +41,26 @@
<p class="card-texts">Location: <%= @job.cities.map(&:location).join(',') %></p> <p class="card-texts">Location: <%= @job.cities.map(&:location).join(',') %></p>
<p class="card-text"><a href="#">Salary: </a><%= @job.salary %></p> <p class="card-text"><a href="#">Salary: </a><%= @job.salary %></p>
<%= simple_format(@job.descripton) %> <%= simple_format(@job.descripton) %>
<a class="btn btn-success text-white w-25" href ="<%= form_apply_path(id: @job.id)%>">Apply</a>
<a class="btn btn-success text-white w-25">Favorite</a> <% if logged_in? && current_user.applied_job?(@job) %>
<%= link_to 'Applied',root_path, {class: 'btn btn-blog text-white w-25'} %>
<h1 class="text-danger mt-5"> You applied this job </h1>
<% elsif logged_in? %>
<%= link_to 'Apply',form_apply_path(job_id: @job.id), {class: 'btn btn-success text-white w-25'} %>
<% else %>
<%= link_to 'Apply',login_user_path, {class: 'btn btn-success text-white w-25'} %>
<% end %>
<div class="btn text-white w-25">
<div id="follow_form_<%= @job.id %>">
<% if current_user.favorite?(@job) %>
<%= render 'favorite/destroy', job_id: @job.id %>
<% else %>
<%= render 'favorite/create', job_id: @job.id %>
<% end %>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -26,12 +26,19 @@ ...@@ -26,12 +26,19 @@
<!--end--> <!--end-->
<% end %> <% end %>
<!--end set-up--> <!--end set-up-->
<% if logged_in? %>
<li> <li>
<%= link_to '#',class: 'btn btn-info distance mt-1 slide' do %> <%= link_to favorite_list_path,class: 'btn btn-info distance mt-1 slide' do %>
<i class="fa fa-heart"></i> Favorite <strong id="followers" class="stat"><%= current_user.favorites.count %></strong>
<% end %>
</li>
<% else %>
<li>
<%= link_to login_user_path,class: 'btn btn-info distance mt-1 slide' do %>
<i class="fa fa-heart"></i> Favorite <i class="fa fa-heart"></i> Favorite
<% end %> <% end %>
</li> </li>
<% end %>
</ul> </ul>
</div> </div>
......
<%= form_for(:favorite_job, url: create_favorite_path, remote: true, method: :post) do |f| %>
<div><%= f.hidden_field :job_id, value: job['job_id'] %></div>
<%= f.submit "Favorite",class: 'fa fa-heartbeat' %>
<% end %>
\ No newline at end of file
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
<%= link_to apply.job.job_title,job_detail_path(apply.job.id),class: 'search_list_jobs_title' %> <%= link_to apply.job.job_title,job_detail_path(apply.job.id),class: 'search_list_jobs_title' %>
<% if apply.job.short_description.present? %> <% if apply.job.short_description.present? %>
<%= binding.pry %>
<li class="detail_description"> <li class="detail_description">
<%= truncate apply.job.short_description,length: 250 %> <%= truncate apply.job.short_description,length: 250 %>
<%= link_to 'read more',job_detail_path(apply.job.id)%></li> <%= link_to 'read more',job_detail_path(apply.job.id)%></li>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<h1 class="text-center mt-5 text-danger">Applied Jobs</h1> <h1 class="text-center mt-5 text-danger">Applied Jobs</h1>
<div class="mt-4"> <div class="mt-4">
<%= paginate @job_pages,theme: 'twitter-bootstrap-4'%> <%= paginate @jobs,theme: 'twitter-bootstrap-4'%>
<%= render partial: "my_jobs",collection: @job, as: :apply %> <%= render partial: "my_jobs",collection: @jobs, as: :apply %>
<%= paginate @job_pages,theme: 'twitter-bootstrap-4'%> <%= paginate @jobs,theme: 'twitter-bootstrap-4'%>
</div> </div>
\ No newline at end of file
...@@ -37,12 +37,7 @@ Rails.application.routes.draw do ...@@ -37,12 +37,7 @@ Rails.application.routes.draw do
get '/favorites',controller: :favorite,action: :favorite_list,as: :favorite_jobs get '/favorites',controller: :favorite,action: :favorite_list,as: :favorite_jobs
post '/favorites',controller: :favorite,action: :create,as: :create_favorite post '/favorites',controller: :favorite,action: :create,as: :create_favorite
delete '/favorites',controller: :favorite,action: :destroy,as: :destroy_favorite
resources :users do get '/favorite_list',controller: :favorite,action: :favorite_list,as: :favorite_list
member do
get :following, :followers, :favorite
end
end
# resources :favorite, only: [:create, :destroy]
mount Sidekiq::Web => '/sidekiq' mount Sidekiq::Web => '/sidekiq'
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