Commit 9bed3589 by Ba Toi Dang

Merge branch 'features/create_favourite_pages' into 'master'

create favorite_job page

See merge request !6
parents 051d5416 c7bffa9a
...@@ -81,9 +81,17 @@ body{ ...@@ -81,9 +81,17 @@ body{
.maxH89{ .maxH89{
max-height: 89px; max-height: 89px;
} }
// end
// Message // Message
.message{ .message{
position: fixed; right: 0 position: fixed; right: 0
} }
// Table
.position-relative{
position: relative !important;
}
.mid-heigth{
position: absolute;
top: 25%;
}
class FavoritesController < ApplicationController
before_action :authenticate_user!
def index
@jobs = current_user.liked_jobs.includes(:company)
end
def user_like_job
job = Job.find(params[:job_id])
flash[:notice] = 'Successfully favorited...'
flash[:notice] = 'You have favorited this job already' unless current_user.like_job(job)
redirect_back(fallback_location: root_path)
end
def user_unlike_job
job = Job.find(params[:job_id])
current_user.unlike_job(job)
flash[:notice] = 'Successfully unfavorited...'
redirect_back(fallback_location: root_path)
end
end
...@@ -15,11 +15,26 @@ class User < ApplicationRecord ...@@ -15,11 +15,26 @@ class User < ApplicationRecord
mount_uploader :cv, CvUploader mount_uploader :cv, CvUploader
# Validate # Validate
validates :email, presence: true, length: {maximum: 200} validates :email, presence: true, length: { maximum: 200 }
validates :name, presence: true, length: {maximum: 200}, unless: :skip_validation validates :name, presence: true, length: { maximum: 200 }, unless: :skip_validation
validates_size_of :cv, maximum: 5.megabytes, message: "size should be less than 5MB" validates_size_of :cv, maximum: 5.megabytes, message: 'size should be less than 5MB'
def like_job(job)
return false if liked?(job)
liked_jobs << job
true
end
def unlike_job(job)
liked_jobs.delete(job.id)
end
def liked?(job)
liked_jobs.include?(job)
end
private private
def password_required? def password_required?
return false if skip_validation return false if skip_validation
super super
......
<div class="row">
<div class="container">
<div class="jobs clearfix">
<div class="job col-md-12">
<table class="table">
<tbody>
<%- @jobs.each do |job|-%>
<tr>
<td class="col-md-1 position-relative">
<input type="radio" name="rbn-apply-job" class="mid-heigth">
</td>
<td class="col-md-9">
<h4 class="mr0"><%= link_to job.name, job_path(job) %></h4>
<p><%= "Loacation: #{job.company.location}" %></p>
<p><%= "Salary: #{job.salary}" %></p>
</td>
<td class="col-md-2 position-relative">
<%= button_to "Remove",
unlike_job_favorites_path(job_id: job.id),
data: {confirm: "Are you sure you want to remove this job?"},
class: "btn btn-danger btn-lg mid-heigth" %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<%= button_to "Apply", nil, class: "btn btn-primary" %>
</div>
</div>
</div>
<div class="row"> <div class="row">
<div class="container"> <div class="container">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li><a href="/">TOP</a></li> <li><%= link_to "TOP", root_path %></li>
<li> <li>
<%- @job.cities.each_with_index do |city, index| -%> <%- @job.cities.each_with_index do |city, index| -%>
<%= "#{index > 0 ? ',' : ''}" %> <%= "#{index > 0 ? ',' : ''}" %>
...@@ -37,13 +37,15 @@ ...@@ -37,13 +37,15 @@
</div> </div>
<div class="action"> <div class="action">
<div class="col-md-6"> <div class="col-md-6">
<%= link_to "Apply", apply_applies_path(job_id: @job.id), class: "btn btn-default btn-lg" %> <%= link_to "Apply", apply_applies_path(job_id: @job.id), class: "btn btn-primary btn-lg" %>
</div> </div>
<div class="action">
<div class="col-md-6"> <div class="col-md-6">
<%= link_to "Favorite", "#", class: "btn btn-default btn-lg" %> <%= button_to "Favorite",
job_favorites_path(job_id: @job.id),
class: "btn btn-primary btn-lg" %>
</div>
</div> </div>
</div> </div>
</div> </div>
</div>
</div> </div>
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<!-- check an user is logged in or not --> <!-- check an user is logged in or not -->
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<%- if current_user -%> <%- if current_user -%>
<li><a href="#"><i class="fa fa-sign-in" aria-hidden="true"></i> My Page</a></li> <li><a href="#"><i class="fa fa-user" aria-hidden="true"></i> My Page</a></li>
<li> <li>
<%= link_to destroy_user_session_path, method: :delete do %> <%= link_to destroy_user_session_path, method: :delete do %>
<i class="fa fa-sign-out" aria-hidden="true"></i>Logout <i class="fa fa-sign-out" aria-hidden="true"></i>Logout
...@@ -21,9 +21,17 @@ ...@@ -21,9 +21,17 @@
<i class="fa fa-plus-circle" aria-hidden="true"></i> Register <i class="fa fa-plus-circle" aria-hidden="true"></i> Register
<% end %> <% end %>
</li> </li>
<li><a href="#"><i class="fa fa-plus" aria-hidden="true"></i> Register</a></li> <li>
<%= link_to new_user_session_path do %>
<i class="fa fa-sign-in" aria-hidden="true"></i> Login
<% end %>
</li>
<%- end -%> <%- end -%>
<li><a href="#"><i class="fa fa-star" aria-hidden="true"></i></span> Favorite</a></li> <li>
<%= link_to favorites_path do %> Favorite
<i class="fa fa-star" aria-hidden="true"></i>
<% end %>
</li>
<li><a href="#"><i class="fa fa-history" aria-hidden="true"></i></span> History</a></li> <li><a href="#"><i class="fa fa-history" aria-hidden="true"></i></span> History</a></li>
</ul> </ul>
</div> </div>
......
...@@ -48,16 +48,16 @@ Rails.application.configure do ...@@ -48,16 +48,16 @@ Rails.application.configure do
# Raises error for missing translations # Raises error for missing translations
# config.action_view.raise_on_missing_translations = true # config.action_view.raise_on_missing_translations = true
# config.action_mailer.delivery_method = :smtp config.action_mailer.delivery_method = :smtp
# config.action_mailer.smtp_settings = { address: 'localhost', config.action_mailer.smtp_settings = { address: 'localhost',
# port: 1025 } port: 1025 }
config.action_mailer.smtp_settings = { # config.action_mailer.smtp_settings = {
address: "smtp.gmail.com", # address: "smtp.gmail.com",
port: 587, # port: 587,
domain: "example.com", # domain: "example.com",
authentication: "plain", # authentication: "plain",
enable_starttls_auto: true, # enable_starttls_auto: true,
user_name: ENV["GMAIL_USER"], # user_name: ENV["GMAIL_USER"],
password: ENV["GMAIL_PASSWORD"] # password: ENV["GMAIL_PASSWORD"]
} # }
end end
...@@ -9,6 +9,12 @@ Rails.application.routes.draw do ...@@ -9,6 +9,12 @@ Rails.application.routes.draw do
resources :cities, only: [:index, :show] resources :cities, only: [:index, :show]
resources :industries, only: [:index, :show] resources :industries, only: [:index, :show]
resources :favorites do
collection do
post :user_like_job, as: :job
post :user_unlike_job, as: :unlike_job
end
end
resources :jobs do resources :jobs do
collection do collection do
get 'city/:city_id' => "jobs#city", as: :city get 'city/:city_id' => "jobs#city", as: :city
......
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