Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venjobs_app
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
Quang Vinh Nguyen
venjobs_app
Commits
fc55b92c
Commit
fc55b92c
authored
Jun 21, 2018
by
Quang Vinh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update ActiveRecord -- RecordNotFound handle
parent
08d9d237
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
23 deletions
+21
-23
app/controllers/application_controller.rb
+13
-0
app/controllers/jobs_controller.rb
+8
-20
app/models/job.rb
+0
-3
No files found.
app/controllers/application_controller.rb
View file @
fc55b92c
class
ApplicationController
<
ActionController
::
Base
rescue_from
ActiveRecord
::
RecordNotFound
,
with: :record_not_found
protected
def
record_not_found
respond_to
do
|
format
|
format
.
html
{
render
file:
"
#{
Rails
.
root
}
/public/404"
,
layout:
false
,
status: :not_found
}
format
.
xml
{
head
:not_found
}
format
.
any
{
head
:not_found
}
end
end
end
app/controllers/jobs_controller.rb
View file @
fc55b92c
# frozen_string_literal: true
class
JobsController
<
ApplicationController
# rescue_from ActiveRecord::RecordNotFound, with: :job_not_found
def
index
search_str
=
params
[
:search
].
blank?
?
'*'
:
params
[
:search
]
job_found
=
Job
.
search
(
kw:
search_str
,
page:
params
[
:page
].
to_i
)
@job_ids
=
job_found
[
:job_id
]
@job_num
=
job_found
[
:num
]
job_search_result
=
Job
.
where
(
id:
@
job_ids
)
search_str
=
params
[
:search
].
blank?
?
'*'
:
params
[
:search
]
job_found
=
Job
.
search
(
kw:
search_str
,
page:
params
[
:page
].
to_i
)
job_ids
=
job_found
[
:job_id
]
@job_num
=
job_found
[
:num
]
job_search_result
=
Job
.
where
(
id:
job_ids
)
@jobs
=
Kaminari
.
paginate_array
(
job_search_result
,
total_count:
@job_num
).
page
(
params
[
:page
]).
per
(
Kaminari
.
config
.
default_per_page
)
page
(
params
[
:page
])
end
def
show
@job
=
Job
.
find_by
(
id:
params
[
:id
])
unless
@job
.
nil?
return
@job
else
job_not_found
(
params
[
:id
])
end
@job
=
Job
.
find
(
params
[
:id
])
end
def
city
...
...
@@ -37,9 +30,4 @@ class JobsController < ApplicationController
@jobs
=
Job
.
all
.
order
(
updated_at: :desc
).
take
(
5
)
@cities
=
City
.
all
.
select
{
|
city
|
city
.
jobs
.
any?
}.
take
(
8
)
end
def
job_not_found
(
id
)
redirect_to
root_path
flash
[
:danger
]
=
"Couldn't find job id:
#{
id
}
"
end
end
app/models/job.rb
View file @
fc55b92c
# frozen_string_literal: true
class
Job
<
ApplicationRecord
attr_accessor
:page_per
belongs_to
:company
,
foreign_key:
'company_id'
has_many
:cities_jobs
,
foreign_key:
'job_id'
,
...
...
@@ -34,8 +33,6 @@ class Job < ApplicationRecord
validates
:condition
,
presence:
true
,
length:
{
maximum:
1000
}
validates
:link
,
presence:
true
@page_per
=
10
paginates_per
@page_per
def
self
.
search
(
search_hash
=
{
kw:
'*'
,
page:
0
})
jobs
=
{
job_id:
[],
job_num:
0
}
...
...
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