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
0
Merge Requests
0
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
Nguyen Ngoc Nghia
VeNJOB
Commits
9ebefcc0
Commit
9ebefcc0
authored
Mar 05, 2020
by
nnnghia98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check user_jobs exist?
parent
e0aa1263
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
19 additions
and
20 deletions
+19
-20
app/controllers/favorites_controller.rb
+14
-14
app/controllers/jobs_controller.rb
+1
-0
app/views/favorites/create.js.erb
+1
-1
app/views/favorites/destroy.js.erb
+1
-1
app/views/jobs/_job.html.erb
+1
-2
app/views/tops/favorite.html.erb
+0
-2
config/database.yml
+1
-0
No files found.
app/controllers/favorites_controller.rb
View file @
9ebefcc0
class
FavoritesController
<
ApplicationController
class
FavoritesController
<
ApplicationController
before_action
:authenticate_user!
,
only:
[
:create
,
:destroy
]
before_action
:authenticate_user!
,
only:
[
:create
,
:destroy
]
before_action
:find_favorited_job
,
only:
[
:create
,
:destroy
]
def
create
def
create
redirect_to
new_user_session_path
unless
user_signed_in?
redirect_to
jobs_path
if
params
[
:id
].
blank?
redirect_to
jobs_path
if
@job
.
id
.
blank?
job_id
=
params
[
:id
]
job_id
=
@job
.
id
if
get_user_job
@all_favorite_job
.
find_by
(
job_id:
job_id
)
||
@favorite_jobs
=
get_user_job
.
where
.
not
(
favorited_at:
nil
)
||
@all_favorite_job
.
create!
(
user_id:
current_user
.
id
,
job_id:
job_id
,
favorited_at:
Time
.
current
)
get_user_job
.
update
(
favorited_at:
Time
.
current
)
else
redirect_to
job_path
(
job_id
)
@favorite_jobs
=
UserJob
.
create!
(
user_id:
current_user
.
id
,
job_id:
job_id
,
favorited_at:
Time
.
current
)
end
end
end
def
destroy
def
destroy
redirect_to
new_user_session_path
unless
user_signed_in?
redirect_to
jobs_path
if
@job
.
id
.
blank?
redirect_to
jobs_path
if
@job
.
id
.
blank?
job_id
=
params
[
:id
]
job_id
=
@job
.
id
@favorited_jobs
=
get_user_job
.
where
.
not
(
favorited_at:
nil
)
@
all_favorite_job
.
find_by
(
job_id:
job_id
).
destroy
@
favorited_jobs
=
get_user_job
.
update
(
favorited_at:
nil
)
redirect_to
job_path
(
job_id
)
redirect_to
job_path
(
job_id
)
end
end
private
private
def
find_favorited
_job
def
get_user
_job
@all_favorite_job
=
current_user
.
user_jobs
.
where
.
not
(
favorited_at:
nil
)
UserJob
.
find_by
(
user_id:
current_user
.
id
,
job_id:
params
[
:id
]
)
end
end
end
end
app/controllers/jobs_controller.rb
View file @
9ebefcc0
...
@@ -68,6 +68,7 @@ class JobsController < ApplicationController
...
@@ -68,6 +68,7 @@ class JobsController < ApplicationController
elsif
params
[
:industry_id
]
elsif
params
[
:industry_id
]
redirect_to
jobs_path
unless
Industry
.
find_by
(
id:
params
[
:industry_id
])
redirect_to
jobs_path
unless
Industry
.
find_by
(
id:
params
[
:industry_id
])
end
end
end
def
find_applied_jobs
def
find_applied_jobs
@all_applied_jobs
=
current_user
.
user_jobs
.
where
.
not
(
applied_at:
nil
)
@all_applied_jobs
=
current_user
.
user_jobs
.
where
.
not
(
applied_at:
nil
)
...
...
app/views/favorites/create.js.erb
View file @
9ebefcc0
$("#favorite_form
_
<%=
@job
.
id
%>
").html("
<%=
escape_javascript
(
render
"shared/unfavorite_btn"
,
job:
@job
%>
");
$("#favorite_form").html("
<%=
escape_javascript
(
render
"shared/unfavorite_btn"
,
job:
@job
%>
");
app/views/favorites/destroy.js.erb
View file @
9ebefcc0
$("#favorite_form
_
<%=
@job
.
id
%>
").html("
<%=
escape_javascript
(
render
"shared/favorite_btn"
,
job:
@job
)
%>
");
$("#favorite_form").html("
<%=
escape_javascript
(
render
"shared/favorite_btn"
,
job:
@job
)
%>
");
app/views/jobs/_job.html.erb
View file @
9ebefcc0
...
@@ -17,8 +17,7 @@
...
@@ -17,8 +17,7 @@
<dd>
<%=
job
[
"city"
]
%>
</dd>
<dd>
<%=
job
[
"city"
]
%>
</dd>
</dl>
</dl>
</div>
</div>
<div
id=
"favorite_form_"
>
<div
id=
"favorite_form"
>
<button
type=
"button"
class=
"btn btn-outline-secondary"
>
Favorite
</button>
<%
if
current_user
.
favorites
.
exists?
(
job_id:
job
.
id
)
%>
<%
if
current_user
.
favorites
.
exists?
(
job_id:
job
.
id
)
%>
<%=
render
"shared/unfavorite_btn"
,
job_id:
job
.
id
%>
<%=
render
"shared/unfavorite_btn"
,
job_id:
job
.
id
%>
<%
else
%>
<%
else
%>
...
...
app/views/tops/favorite.html.erb
deleted
100644 → 0
View file @
e0aa1263
<%
provide
(
:title
,
"Favorite"
)
%>
<h1>
VeNJOB Favorite
</h1>
config/database.yml
View file @
9ebefcc0
...
@@ -22,6 +22,7 @@ default: &default
...
@@ -22,6 +22,7 @@ default: &default
secure_auth
:
false
secure_auth
:
false
timeout
:
5000
timeout
:
5000
socket
:
/var/run/mysqld/mysqld.sock
socket
:
/var/run/mysqld/mysqld.sock
reconnect
:
true
development
:
development
:
<<
:
*default
<<
:
*default
...
...
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