Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VeNJob
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tô Ngọc Ánh
VeNJob
Commits
a7e94105
Commit
a7e94105
authored
Aug 20, 2020
by
Tô Ngọc Ánh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
func create, destroy favorite
parent
146f451f
Pipeline
#973
failed with stages
in 0 seconds
Changes
16
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
65 additions
and
23 deletions
+65
-23
app/controllers/applied_jobs_controller.rb
+1
-1
app/controllers/favorites_controller.rb
+5
-4
app/models/applied_job.rb
+1
-1
app/models/favorite.rb
+2
-0
app/models/user.rb
+4
-0
app/views/favorites/_job.html.erb
+25
-0
app/views/favorites/_link_create.html.erb
+0
-4
app/views/favorites/_link_destroy.html.erb
+0
-4
app/views/favorites/_link_favorite.html.erb
+9
-0
app/views/favorites/create.js.erb
+1
-2
app/views/favorites/destroy.js.erb
+2
-3
app/views/favorites/index.html.erb
+10
-0
app/views/jobs/_job.html.erb
+1
-1
app/views/jobs/show.html.erb
+2
-2
app/views/shared/_header.html.erb
+1
-0
config/routes.rb
+1
-1
No files found.
app/controllers/applied_jobs_controller.rb
View file @
a7e94105
...
@@ -2,7 +2,7 @@ class AppliedJobsController < ApplicationController
...
@@ -2,7 +2,7 @@ class AppliedJobsController < ApplicationController
before_action
:authenticate_user!
before_action
:authenticate_user!
def
index
def
index
@applied_jobs
=
Job
.
applied_jobs_of
(
current_user
.
id
).
includes
(
:locations
).
page
(
params
[
:page
])
@applied_jobs
=
Job
.
applied_jobs_of
(
current_user
.
id
).
includes
(
:locations
).
order
(
created_at: :asc
).
page
(
params
[
:page
])
end
end
def
new
def
new
...
...
app/controllers/favorites_controller.rb
View file @
a7e94105
...
@@ -2,7 +2,8 @@ class FavoritesController < ApplicationController
...
@@ -2,7 +2,8 @@ class FavoritesController < ApplicationController
before_action
:authenticate_user!
before_action
:authenticate_user!
def
index
def
index
favorites
=
current_user
.
favorites
.
select
(
:job_id
).
all
@jobs
=
Job
.
where
(
id:
favorites
).
page
(
params
[
:page
])
end
end
def
create
def
create
...
@@ -12,8 +13,8 @@ class FavoritesController < ApplicationController
...
@@ -12,8 +13,8 @@ class FavoritesController < ApplicationController
end
end
def
destroy
def
destroy
@
job
=
Job
.
find_by
(
id:
params
[
:job_id
])
@
favorite
=
current_user
.
favorites
.
find_by
(
job_
id:
params
[
:job_id
])
favorite
=
Favorite
.
find_by
(
id:
params
[
:id
])
@favorite
.
destroy
respond_to
:js
if
favorite
.
destroy
respond_to
:js
end
end
end
end
app/models/applied_job.rb
View file @
a7e94105
...
@@ -7,7 +7,7 @@ class AppliedJob < ApplicationRecord
...
@@ -7,7 +7,7 @@ class AppliedJob < ApplicationRecord
validates
:full_name
,
presence:
true
,
length:
{
maximum:
200
}
validates
:full_name
,
presence:
true
,
length:
{
maximum:
200
}
validates
:email
,
presence:
true
,
format:
{
with:
EMAIL_REGEXN
}
validates
:email
,
presence:
true
,
format:
{
with:
EMAIL_REGEXN
}
validates
:curriculum_vitae
,
presence:
true
validates
:curriculum_vitae
,
presence:
true
validates
:user
,
uniqueness:
{
scope: :job
,
message:
'ha
s already applied this job
'
}
validates
:user
,
uniqueness:
{
scope: :job
,
message:
'ha
ve already applied this job.
'
}
mount_uploader
:curriculum_vitae
,
CurriculumVitaeUploader
mount_uploader
:curriculum_vitae
,
CurriculumVitaeUploader
end
end
app/models/favorite.rb
View file @
a7e94105
class
Favorite
<
ApplicationRecord
class
Favorite
<
ApplicationRecord
belongs_to
:user
belongs_to
:user
belongs_to
:job
belongs_to
:job
validates
:user
,
uniqueness:
{
scope: :job
,
message:
'have already favorited this job.'
}
end
end
app/models/user.rb
View file @
a7e94105
...
@@ -11,4 +11,8 @@ class User < ApplicationRecord
...
@@ -11,4 +11,8 @@ class User < ApplicationRecord
devise
:database_authenticatable
,
:registerable
,
devise
:database_authenticatable
,
:registerable
,
:recoverable
,
:rememberable
,
:validatable
,
:recoverable
,
:rememberable
,
:validatable
,
:confirmable
:confirmable
def
favorited?
(
job_id
)
favorites
.
find_by
(
job_id:
job_id
).
present?
end
end
end
app/views/favorites/_job.html.erb
0 → 100644
View file @
a7e94105
<%=
form_tag
new_applied_job_path
,
method: :get
,
enforce_utf8:
false
do
%>
<%=
collection_radio_buttons
(
:job_id
,
params
[
:job_id
],
@jobs
,
:id
,
:title
)
do
|
radio
|
%>
<div
class=
'card flex-md-row align-items-center my-2'
>
<%=
radio
.
radio_button
(
class:
"ml-3"
)
%>
<div
class=
'card-body'
>
<%=
link_to
radio
.
object
.
title
,
job_path
(
radio
.
object
),
class:
'card-title font-weight-bold text-decoration-none'
%>
<p
class=
'card-text'
>
<%=
radio
.
object
.
company
.
name
%>
</p>
<p
class=
'mb-0'
>
<strong>
Work place:
</strong>
<%
radio
.
object
.
locations
.
each
do
|
location
|
%>
<%=
location
.
city
%>
<%
end
%>
</p>
<p><strong>
Salary:
</strong>
<%=
radio
.
object
.
salary
%>
</p>
<p
class=
'card-text'
>
<%=
strip_tags
(
radio
.
object
.
description
).
truncate
(
Job
::
WORDS_SHORT_DESCRIPTION
)
%>
</p>
</div>
<div
id=
"favorite-
<%=
radio
.
object
.
id
%>
"
class=
'p-2'
>
<%=
render
'favorites/link_favorite'
,
job_id:
radio
.
object
.
id
%>
</div>
</div>
<%
end
%>
<div
class=
"actions text-center"
>
<%=
submit_tag
'Apply Now'
,
name:
nil
,
class:
'btn btn-outline-success btn-lg'
%>
</div>
<%
end
%>
app/views/favorites/_link_create.html.erb
deleted
100644 → 0
View file @
146f451f
<%=
link_to
'Favorite'
,
job_favorites_path
(
job
),
method: :post
,
class:
'btn btn-outline-danger btn-lg'
,
remote:
true
,
disable_with:
'<i class="fa fa-spinner fa-spin"></i>'
.
html_safe
%>
\ No newline at end of file
app/views/favorites/_link_destroy.html.erb
deleted
100644 → 0
View file @
146f451f
<%=
link_to
'Unfavorite'
,
job_favorite_path
(
job_id:
job_id
,
id:
favorite_id
),
method: :delete
,
class:
'btn btn-outline-secondary btn-lg'
,
remote:
true
,
disable_with:
'<i class="fa fa-spinner fa-spin"></i>'
.
html_safe
%>
\ No newline at end of file
app/views/favorites/_link_favorite.html.erb
0 → 100644
View file @
a7e94105
<%
if
user_signed_in?
&&
current_user
.
favorited?
(
job_id
)
%>
<%=
link_to
'Unfavorite'
,
job_favorite_path
(
job_id
),
method: :delete
,
class:
'btn btn-danger btn-lg'
,
remote:
true
,
data:
{
disable_with:
'<i class="fa fa-spinner fa-spin"></i>'
.
html_safe
}
%>
<%
else
%>
<%=
link_to
'Favorite'
,
job_favorites_path
(
job_id:
job_id
),
method: :post
,
class:
'btn btn-outline-danger btn-lg'
,
remote:
true
,
data:
{
disable_with:
'<i class="fa fa-spinner fa-spin"></i>'
.
html_safe
}
%>
<%
end
%>
app/views/favorites/create.js.erb
View file @
a7e94105
$('#favorite-
<%=
@job
.
id
%>
')
$('#favorite-
<%=
@job
.
id
%>
')
.html("
<%=
j
render
'favorites/link_destroy'
,
job_id:
@job
.
id
,
favorite_id:
@favorite
.
id
%>
")
.html("
<%=
j
render
'favorites/link_favorite'
,
job_id:
@job
.
id
%>
")
\ No newline at end of file
app/views/favorites/destroy.js.erb
View file @
a7e94105
$('#favorite-
<%=
@job
.
id
%>
')
$('#favorite-
<%=
@favorite
.
job_id
%>
')
.html("
<%=
j
render
'favorites/link_create'
,
job:
@job
%>
")
.html("
<%=
j
render
'favorites/link_favorite'
,
job_id:
@favorite
.
job_id
%>
")
\ No newline at end of file
app/views/favorites/index.html.erb
View file @
a7e94105
<div
class=
"my-4"
>
<h3
class=
'text-center'
>
Favorited Jobs
</h3>
<hr
class=
"divider"
>
<div
class=
'content'
>
<%=
paginate
@jobs
%>
<%=
render
'favorites/job'
,
jobs:
@jobs
%>
<%=
paginate
@jobs
%>
</div>
</div>
\ No newline at end of file
app/views/jobs/_job.html.erb
View file @
a7e94105
...
@@ -12,6 +12,6 @@
...
@@ -12,6 +12,6 @@
<p
class=
'card-text'
>
<%=
strip_tags
(
job
.
description
).
truncate
(
Job
::
WORDS_SHORT_DESCRIPTION
)
%>
</p>
<p
class=
'card-text'
>
<%=
strip_tags
(
job
.
description
).
truncate
(
Job
::
WORDS_SHORT_DESCRIPTION
)
%>
</p>
</div>
</div>
<div
id=
"favorite-
<%=
job
.
id
%>
"
class=
'p-2'
>
<div
id=
"favorite-
<%=
job
.
id
%>
"
class=
'p-2'
>
<%=
render
'favorites/link_
create'
,
job:
job
%>
<%=
render
'favorites/link_
favorite'
,
job_id:
job
.
id
%>
</div>
</div>
</div>
</div>
app/views/jobs/show.html.erb
View file @
a7e94105
...
@@ -42,7 +42,7 @@
...
@@ -42,7 +42,7 @@
<%=
link_to
'Apply Now'
,
'#'
,
class:
'btn btn-outline-secondary btn-lg disabled'
%>
<%=
link_to
'Apply Now'
,
'#'
,
class:
'btn btn-outline-secondary btn-lg disabled'
%>
<%
end
%>
<%
end
%>
</div>
</div>
<div
class=
"col-6 text-left"
>
<div
id=
"favorite-
<%=
@job
.
id
%>
"
class=
"col-6 text-left"
>
<%=
link_to
'Favorite'
,
'#'
,
class:
'btn btn-outline-danger btn-lg'
%>
<%=
render
'favorites/link_favorite'
,
job_id:
@job
.
id
%>
</div>
</div>
</div>
</div>
app/views/shared/_header.html.erb
View file @
a7e94105
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
<%
if
user_signed_in?
%>
<%
if
user_signed_in?
%>
<li
class=
"nav-item"
>
<li
class=
"nav-item"
>
<%=
link_to
my_favorites_path
,
class:
'nav-link text-white'
,
title:
'Favorite'
do
%>
<%=
link_to
my_favorites_path
,
class:
'nav-link text-white'
,
title:
'Favorite'
do
%>
<small>
<%=
current_user
.
favorites
.
size
%>
</small>
<i
class=
"fas fa-heart"
></i>
<i
class=
"fas fa-heart"
></i>
<%
end
%>
<%
end
%>
</li>
</li>
...
...
config/routes.rb
View file @
a7e94105
...
@@ -11,7 +11,7 @@ Rails.application.routes.draw do
...
@@ -11,7 +11,7 @@ Rails.application.routes.draw do
get
'my/jobs'
,
to:
'applied_jobs#index'
,
as: :my_applied_jobs
get
'my/jobs'
,
to:
'applied_jobs#index'
,
as: :my_applied_jobs
get
'my/favorite'
,
to:
'favorites#index'
,
as: :my_favorites
get
'my/favorite'
,
to:
'favorites#index'
,
as: :my_favorites
post
'jobs/:job_id/favorites'
,
to:
'favorites#create'
,
as: :job_favorites
post
'jobs/:job_id/favorites'
,
to:
'favorites#create'
,
as: :job_favorites
delete
'jobs/:job_id/favorites
/:id
'
,
to:
'favorites#destroy'
,
as: :job_favorite
delete
'jobs/:job_id/favorites'
,
to:
'favorites#destroy'
,
as: :job_favorite
resources
:users
,
only: :show
resources
:users
,
only: :show
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment