Commit a03072fc by thanhnd

add favorites job with button

parent 5e04a98f
Pipeline #607 canceled with stages
in 0 seconds
...@@ -3,6 +3,7 @@ class JobsController < ApplicationController ...@@ -3,6 +3,7 @@ class JobsController < ApplicationController
@job_detail = Job.find_by_id(params[:id]) @job_detail = Job.find_by_id(params[:id])
if current_user if current_user
HistoryJob.find_or_create_by(job_id: @job_detail.id, user_id: current_user.id) HistoryJob.find_or_create_by(job_id: @job_detail.id, user_id: current_user.id)
SavedJob.find_or_create_by(job_id: @job_detail.id, user_id: current_user.id)
end end
end end
...@@ -15,6 +16,15 @@ class JobsController < ApplicationController ...@@ -15,6 +16,15 @@ class JobsController < ApplicationController
end end
end end
def favorites
@favjobs = SavedJob.job_by_id(current_user.id)
@fj = []
@favjobs.each do |favjob|
@fj << Job.find(favjob.job_id)
end
end
def index def index
@job_count = Job.count @job_count = Job.count
pagin = params[:page].to_i > 0 ? params[:page].to_i : 1 pagin = params[:page].to_i > 0 ? params[:page].to_i : 1
......
class SavedJob < ApplicationRecord class SavedJob < ApplicationRecord
belongs_to :job belongs_to :job
belongs_to :user belongs_to :user
def self.job_by_id(user_id)
select('job_id').where(user_id: user_id)
end
end end
<div id="search" class="container p-5 my-2 bg-secondary text-white">
<!-- Search form -->
<form class="form-inline md-form mr-auto mb-4">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-warning btn-rounded btn-sm my-0" type="submit">Search</button>
</form>
</div>
<div id="job_favorites"class="container p-5 my-2 bg-secondary text-white">
<% if @favjobs.nil? == true %>
<div> This id is not available. </div>
<% else %>
<font color="red"><b><label > Favorites - Job :</label></b></font>
<ul>
<% @fj.each do |j| %>
<li><%= link_to j.job_name, job_detail_url(j.id) %></li>
<li><%= j.salary %></li>
<li><%= j.level %></li>
<li><%= j.experience %></li>
<li ><span class="text"><%= j.description %></span>
</li>
<br>
<% end %>
</ul>
<% end %>
</div>
...@@ -24,9 +24,6 @@ ...@@ -24,9 +24,6 @@
<br> <br>
<% end %> <% end %>
</ul> </ul>
<button class="button button1">Apply</button>
<button class="button button2">Favorites</button>
<% end %> <% end %>
</div> </div>
......
...@@ -28,7 +28,11 @@ ...@@ -28,7 +28,11 @@
<li ><span class="text"><%= @job_detail.description %></span> <li ><span class="text"><%= @job_detail.description %></span>
</li> </li>
</ul> </ul>
<%= link_to '/detail/:id', remote: true do %>
<button class="button button1">Apply</button> <button class="button button1">Apply</button>
<% end %>
<button class="button button2">Favorites</button> <button class="button button2">Favorites</button>
<% end %> <% end %>
</div> </div>
......
...@@ -12,6 +12,7 @@ Rails.application.routes.draw do ...@@ -12,6 +12,7 @@ Rails.application.routes.draw do
get 'detail/:id', to: 'jobs#show', as: :job_detail get 'detail/:id', to: 'jobs#show', as: :job_detail
get 'history', to: 'jobs#history' get 'history', to: 'jobs#history'
get 'favorites', to: 'jobs#favorites'
get 'jobs/search' => 'jobs#search', as: :job_search get 'jobs/search' => 'jobs#search', as: :job_search
root 'top_page#index' root 'top_page#index'
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
......
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