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
14ac61dc
Commit
14ac61dc
authored
Mar 06, 2020
by
nnnghia98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix conflict between fav and apply button
parent
9ebefcc0
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
36 additions
and
31 deletions
+36
-31
app/controllers/favorites_controller.rb
+11
-11
app/controllers/jobs_controller.rb
+3
-2
app/helpers/job_helper.rb
+8
-0
app/views/favorites/create.js.erb
+0
-1
app/views/favorites/destroy.js.erb
+1
-1
app/views/favorites/unfavorite.js.erb
+1
-0
app/views/jobs/_job.html.erb
+0
-7
app/views/jobs/show.html.erb
+8
-1
app/views/shared/_favorite_btn.html.erb
+1
-1
app/views/shared/_unfavorite_btn.html.erb
+1
-1
config/routes.rb
+2
-6
No files found.
app/controllers/favorites_controller.rb
View file @
14ac61dc
class
FavoritesController
<
ApplicationController
class
FavoritesController
<
ApplicationController
before_action
:authenticate_user!
,
only:
[
:
create
,
:destroy
]
before_action
:authenticate_user!
,
only:
[
:
favorite
,
:unfavorite
]
def
crea
te
def
favori
te
redirect_to
jobs_path
if
params
[
:id
].
blank?
redirect_to
jobs_path
if
params
[
:
job_
id
].
blank?
job_id
=
params
[
:id
]
job_id
=
params
[
:
job_
id
]
if
get_user_job
if
get_user_job
@favorite_jobs
=
get_user_job
.
where
.
not
(
favorited_at:
nil
)
||
@favorite_jobs
=
get_user_job
.
update
(
favorited_at:
Time
.
current
)
get_user_job
.
update
(
favorited_at:
Time
.
current
)
else
else
@favorite_jobs
=
UserJob
.
create!
(
user_id:
current_user
.
id
,
job_id:
job_id
,
favorited_at:
Time
.
current
)
@favorite_jobs
=
UserJob
.
create!
(
user_id:
current_user
.
id
,
job_id:
job_id
,
favorited_at:
Time
.
current
)
end
end
redirect_to
job_path
(
job_id
)
end
end
def
destroy
def
unfavorite
redirect_to
jobs_path
if
@job
.
id
.
blank?
redirect_to
jobs_path
if
params
[
:job_id
]
.
blank?
job_id
=
params
[
:id
]
job_id
=
params
[
:
job_
id
]
@favorited_jobs
=
get_user_job
.
where
.
not
(
favorited_at:
nil
)
@favorited_jobs
=
get_user_job
.
update
(
favorited_at:
nil
)
@favorited_jobs
=
get_user_job
.
update
(
favorited_at:
nil
)
redirect_to
job_path
(
job_id
)
redirect_to
job_path
(
job_id
)
...
@@ -26,6 +26,6 @@ class FavoritesController < ApplicationController
...
@@ -26,6 +26,6 @@ class FavoritesController < ApplicationController
private
private
def
get_user_job
def
get_user_job
UserJob
.
find_by
(
user_id:
current_user
.
id
,
job_id:
params
[
:id
])
UserJob
.
find_by
(
user_id:
current_user
.
id
,
job_id:
params
[
:
job_
id
])
end
end
end
end
app/controllers/jobs_controller.rb
View file @
14ac61dc
class
JobsController
<
ApplicationController
class
JobsController
<
ApplicationController
before_action
:authenticate_user!
,
only:
[
:apply
,
:confirm_apply
,
:finish_apply
]
before_action
:authenticate_user!
,
only:
[
:apply
,
:confirm_apply
,
:finish_apply
,
:index
,
:show
]
before_action
:find_user
,
only: :apply_available
before_action
:find_user
,
only: :apply_available
before_action
:validate_city_industry
,
only: :index
before_action
:validate_city_industry
,
only: :index
before_action
:find_applied_jobs
,
only:
[
:apply
,
:confirm_apply
,
:finish_apply
]
before_action
:find_applied_jobs
,
only:
[
:apply
,
:confirm_apply
,
:finish_apply
]
...
@@ -49,7 +49,8 @@ class JobsController < ApplicationController
...
@@ -49,7 +49,8 @@ class JobsController < ApplicationController
end
end
def
apply_available
def
apply_available
user_jobs
.
find_by
(
job_id:
@job_id
,
user_id:
@user
.
id
)
binding
.
pry
user_jobs
.
where
.
not
(
applied_at:
nil
).
find_by
(
job_id:
@job_id
,
user_id:
@user
.
id
)
end
end
private
private
...
...
app/helpers/job_helper.rb
View file @
14ac61dc
...
@@ -7,4 +7,12 @@ module JobHelper
...
@@ -7,4 +7,12 @@ module JobHelper
def
job_applied_at
(
job
)
def
job_applied_at
(
job
)
job
.
user_jobs
.
find_by
(
user_id:
current_user
.
id
).
applied_at
job
.
user_jobs
.
find_by
(
user_id:
current_user
.
id
).
applied_at
end
end
def
verify_favorited_job
UserJob
.
where
.
not
(
favorited_at:
nil
).
find_by
(
user_id:
current_user
.
id
,
job_id:
@job
.
id
)
end
def
verify_applied_job
UserJob
.
where
.
not
(
applied_at:
nil
).
find_by
(
user_id:
current_user
.
id
,
job_id:
@job
.
id
)
end
end
end
app/views/favorites/create.js.erb
deleted
100644 → 0
View file @
9ebefcc0
$("#favorite_form").html("
<%=
escape_javascript
(
render
"shared/unfavorite_btn"
,
job:
@job
%>
");
app/views/favorites/destroy.js.erb
View file @
14ac61dc
$("#favorite_form").html("
<%=
escape_javascript
(
render
"shared/favorite_btn"
,
job:
@job
)
%>
");
$("#favorite_form").html("
<%=
escape_javascript
(
render
"shared/favorite_btn"
)
%>
");
app/views/favorites/unfavorite.js.erb
0 → 100644
View file @
14ac61dc
$("#favorite_form").html("
<%=
escape_javascript
(
render
"shared/unfavorite_btn"
)
%>
");
app/views/jobs/_job.html.erb
View file @
14ac61dc
...
@@ -17,11 +17,4 @@
...
@@ -17,11 +17,4 @@
<dd>
<%=
job
[
"city"
]
%>
</dd>
<dd>
<%=
job
[
"city"
]
%>
</dd>
</dl>
</dl>
</div>
</div>
<div
id=
"favorite_form"
>
<%
if
current_user
.
favorites
.
exists?
(
job_id:
job
.
id
)
%>
<%=
render
"shared/unfavorite_btn"
,
job_id:
job
.
id
%>
<%
else
%>
<%=
render
"shared/favorite_btn"
,
job_id:
job
.
id
%>
<%
end
%>
</div>
</div>
</div>
app/views/jobs/show.html.erb
View file @
14ac61dc
...
@@ -31,8 +31,15 @@
...
@@ -31,8 +31,15 @@
</div>
</div>
<div
class=
"job_detail_button"
>
<div
class=
"job_detail_button"
>
<div
id=
"favorite_form"
>
<%
if
verify_favorited_job
%>
<%=
render
"shared/unfavorite_btn"
%>
<%
else
%>
<%=
render
"shared/favorite_btn"
%>
<%=
render
"shared/favorite_btn"
%>
<%
if
user_signed_in?
&&
@job
.
apply_available
(
current_user
)
%>
<%
end
%>
</div>
<%
if
user_signed_in?
&&
verify_applied_job
%>
<button
type=
"button"
class=
"btn btn-primary float-right mx-3"
disabled
>
Apply
</button>
<button
type=
"button"
class=
"btn btn-primary float-right mx-3"
disabled
>
Apply
</button>
<%
else
%>
<%
else
%>
<%=
link_to
"Apply"
,
apply_path
(
job_id:
@job
.
id
),
class:
"btn btn-primary float-right mx-3"
%>
<%=
link_to
"Apply"
,
apply_path
(
job_id:
@job
.
id
),
class:
"btn btn-primary float-right mx-3"
%>
...
...
app/views/shared/_favorite_btn.html.erb
View file @
14ac61dc
<%
if
user_signed_in?
%>
<%
if
user_signed_in?
%>
<%=
form_tag
(
jobs_favorites_path
(
job_id:
@job
.
id
)
,
remote:
true
)
do
%>
<%=
form_tag
(
favorite_path
(
job_id:
@job
.
id
)
,
remote:
true
)
do
%>
<%=
submit_tag
"Favorite"
,
class:
"btn btn-primary float-right"
%>
<%=
submit_tag
"Favorite"
,
class:
"btn btn-primary float-right"
%>
<%
end
%>
<%
end
%>
<%
else
%>
<%
else
%>
...
...
app/views/shared/_unfavorite_btn.html.erb
View file @
14ac61dc
<%
if
user_signed_in?
%>
<%
if
user_signed_in?
%>
<%=
form_tag
(
jobs_favorite_path
(
job_id:
@job
.
id
),
method: :delete
,
remote:
true
)
do
%>
<%=
form_tag
(
unfavorite_path
(
job_id:
@job
.
id
)
,
remote:
true
)
do
%>
<%=
submit_tag
"Unfavorite"
,
class:
"btn btn-primary float-right"
%>
<%=
submit_tag
"Unfavorite"
,
class:
"btn btn-primary float-right"
%>
<%
end
%>
<%
end
%>
<%
else
%>
<%
else
%>
...
...
config/routes.rb
View file @
14ac61dc
...
@@ -21,11 +21,7 @@ Rails.application.routes.draw do
...
@@ -21,11 +21,7 @@ Rails.application.routes.draw do
end
end
end
end
get
"admin"
,
to:
"admins#index"
,
as: :admin
get
"admin"
,
to:
"admins#index"
,
as: :admin
resource
:favorites
,
only:
[
:create
,
:destroy
]
# post "favorite", to: "favorites#create"
# delete "unfavorite", to: "favorites#destroy"
resource
:jobs
do
post
"favorite"
,
to:
"favorites#favorite"
resource
:favorites
,
only:
[
:create
,
:destroy
]
post
"unfavorite"
,
to:
"favorites#unfavorite"
end
end
end
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