Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/admin/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
column do
panel "代表者一覧" do
li link_to('[ダウンロード] 参加団体メーリングリスト', download_group_list_admin_groups_path(format: 'csv'))
li link_to('代表者連絡先一覧', representative_contact_pages_representative_contact_sheet_path(format: 'pdf'))
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/representative_contact_pages.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/representative_contact_pages.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the RepresentativeContactPages controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
24 changes: 24 additions & 0 deletions app/controllers/representative_contact_pages_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class RepresentativeContactPagesController < ApplicationController
def preview_pdf_page(template_name, output_file_name)
respond_to do |format|
format.pdf do
html = render_to_string template: "representative_contact_pages/#{template_name}"

pdf = PDFKit.new(html, encoding: "UTF-8")

send_data pdf.to_pdf,
filename: "参加団体連絡先_#{output_file_name}.pdf",
type: "application/pdf",
disposition: "inline"
end
end
end

def representative_contact_sheet
this_year = FesYear.this_year

@groups = Group.year(this_year)

preview_pdf_page('representative_contact_sheet', "代表者連絡先一覧")
end
end
9 changes: 9 additions & 0 deletions app/helpers/representative_contact_pages_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module RepresentativeContactPagesHelper
def get_subrep_by_group(group_id)
SubRep.where(group_id:group_id)
end

def get_user_detail_by_group(group_user_id)
UserDetail.where(user_id:group_user_id)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<style type='text/css'>
body {
font-family: "IPAGothic"
}
table {
border-collapse: separate;
border-spacing: 0;
vertical-align: middle;
width: 100%;
table-layout: fixed;
word-wrap:break-word;
}
caption, th, td {
text-align: center;
font-weight: normal;
vertical-align: middle;
border: solid 1px;
padding: 0.5em;
}
.pagebreak{
page-break-after: always;
}
</style>

<div>
<table align='center'>
<tbody>
<tr>
<td width="17%">団体名</td>
<td width="15%">役職</td>
<td width="20%">氏名</td>
<td>電話番号</td>
<td>メールアドレス</td>
</tr>
</tbody>
<% @groups.each do |group| %>
<% row_span = get_subrep_by_group(group.id).try(:length) %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_subrep_by_group(group.id)get_user_detail_by_group(group.user_id) で取得したデータを変数に格納してはどうでしょうか.
何回か同じメソッドを呼んでいますが引数が同じなので,一回取得して後はそれを使いまわすのが良いと思います.データベースに問い合わせする回数が減るので.

<tbody>
<tr>
<td rowspan= "<%= 1 + row_span %>" ><%= group.name %></td>
<td>代表者</td>
<td><%= get_user_detail_by_group(group.user_id).first.name_ja %></td>
<td><%= get_user_detail_by_group(group.user_id).first.tel %></td>
<td><%= User.where(id:group.user_id).first.email %></td>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

アソシエーションを設定しているのでUserレコードはUserDetailレコードから引いてこれます.

user_detail = get_user_detail_by_group(group.user_id)
user = user_detail.user.email # これで参照できる

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そもそも group から取ってこれますね

group.user.email

</tr>
<tr>
<td rowspan="<%= row_span %>">副代表者</td>
<% get_subrep_by_group(group.id).each do |subrep| %>
<td><%= subrep.name_ja %></td>
<td><%= subrep.tel %></td>
<td><%= subrep.email %></td>
</tr>
<% end %>
</tbody>
<% end %>
</table>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
get 'rental_item_pages/for_pasting_room_sheet'

get 'group_information_pages/group_information_sheet'
get 'representative_contact_pages/representative_contact_sheet'

resources :group_project_names
resources :stage_common_options
Expand Down