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
2
Merge Requests
2
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
Thanh Hung Pham
veNJOB
Commits
c94c7c13
Commit
c94c7c13
authored
Jul 19, 2017
by
Thanh Hung Pham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix column csv
parent
03d01c20
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletions
+22
-1
app/controllers/admins_controller.rb
+4
-1
app/models/apply.rb
+18
-0
No files found.
app/controllers/admins_controller.rb
View file @
c94c7c13
...
...
@@ -22,9 +22,12 @@ class AdminsController < ApplicationController
@to_date_default
=
params
[
:to_date
]
if
params
[
:to_date
].
present?
@data
=
Apply
.
search_email
(
@email
).
search_city
(
@city_id
).
search_city
(
@category_id
).
applied_at_between
(
@from_date_default
,
@to_date_default
)
attributes_to_apply
=
%w[id applied_at]
attributes_to_job
=
%w[id name]
attributes_to_user
=
%w[id fullname]
respond_to
do
|
format
|
format
.
html
{
redirect_to
root_url
}
format
.
csv
{
send_data
@data
.
to_csv
}
format
.
csv
{
send_data
@data
.
to_csv
(
attributes_to_apply
,
attributes_to_job
,
attributes_to_user
)
}
end
end
end
app/models/apply.rb
View file @
c94c7c13
...
...
@@ -18,4 +18,22 @@ class Apply < ApplicationRecord
end
end
end
def
self
.
to_csv
(
apply_attributes
=
column_names
,
job_attributes
=
job
.
column_names
,
user_attributes
=
user
.
column_names
,
options
=
{})
CSV
.
generate
(
options
)
do
|
csv
|
csv
.
add_row
apply_attributes
+
job_attributes
+
user_attributes
all
.
each
do
|
apply
|
values
=
apply
.
attributes
.
slice
(
*
apply_attributes
).
values
if
apply
.
job
values
+=
apply
.
job
.
attributes
.
slice
(
*
job_attributes
).
values
end
if
apply
.
user
values
+=
apply
.
user
.
attributes
.
slice
(
*
user_attributes
).
values
end
csv
.
add_row
values
end
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