File tree 5 files changed +45
-5
lines changed
5 files changed +45
-5
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,22 @@ def bulk_insert
75
75
redirect_to book_stocks_url
76
76
end
77
77
78
+ # GET /book_stocks/export
79
+ def export
80
+ @book_stocks = BookStock
81
+ . eager_load ( lending_sets : :customer )
82
+ . eager_load ( :book_master )
83
+ . eager_load ( :book_stock_status )
84
+ . order ( "book_stocks.id, lending_sets.created_at desc" )
85
+ respond_to do |format |
86
+ format . csv do
87
+ send_data render_to_string , filename : 'book_stocks.csv' , type : :csv
88
+ @q = @book_stocks . ransack ( params [ :q ] )
89
+ @q . sorts = "id asc" if @q . sorts . empty?
90
+ end
91
+ end
92
+ end
93
+
78
94
private
79
95
80
96
# Use callbacks to share common setup or constraints between actions.
Original file line number Diff line number Diff line change @@ -9,5 +9,5 @@ def self.ransackable_attributes(_auth_object = nil)
9
9
belongs_to :book_stock_status
10
10
11
11
has_many :lending
12
- has_many :ng_sets , through : :lending
12
+ has_many :lending_sets , through : :lending
13
13
end
Original file line number Diff line number Diff line change
1
+ require 'csv'
2
+
3
+ CSV . generate ( "\xEF \xBB \xBF " ) do |csv |
4
+ csv << %w( id タイトル 状態 貸出セットID 貸出状態 貸出先, 貸出先連絡先 )
5
+ @book_stocks . each do |bs |
6
+ csv << [
7
+ bs . id ,
8
+ bs . book_master . title ,
9
+ bs . book_stock_status . name ,
10
+ bs . lending_sets . target . first ? bs . lending_sets . target . first . id : "" ,
11
+ bs . lending_sets . target . first ? bs . lending_sets . target . first . lending_status . name : "" ,
12
+ bs . lending_sets . target . first ? bs . lending_sets . target . first . customer . name : "" ,
13
+ bs . lending_sets . target . first ? bs . lending_sets . target . first . customer . email_address : ""
14
+ ]
15
+ end
16
+ end
Original file line number Diff line number Diff line change 9
9
<%= render partial : "flash" , locals : { model : Author } %>
10
10
</ div >
11
11
12
+ <%= link_to (
13
+ BookStock . model_name . human + " CSV 出力" ,
14
+ export_book_stocks_path ( format : :csv ) ,
15
+ ) %>
16
+
12
17
<%= form_tag bulk_insert_book_stocks_path , multipart : true do %>
13
18
<%= label_tag "CSVインポート:" %>
14
19
<%= file_field_tag :file , accept : "text/csv" %>
Original file line number Diff line number Diff line change 2
2
resources :lending_sets
3
3
resources :lending_statuses
4
4
resources :customers
5
- resources :customers , except : %w[ new ] do
5
+ resources :customers , except : %w[ import ] do
6
6
collection { post :bulk_insert }
7
7
end
8
+ resources :book_stocks , except : %w[ export ] do
9
+ collection { get :export }
10
+ end
8
11
resources :book_stocks
9
- resources :book_stocks , except : %w[ new ] do
12
+ resources :book_stocks , except : %w[ import ] do
10
13
collection { post :bulk_insert }
11
14
end
12
15
resources :book_stock_statuses
13
16
resources :authors
14
- resources :authors , except : %w[ new ] do
17
+ resources :authors , except : %w[ import ] do
15
18
collection { post :bulk_insert }
16
19
end
17
20
resources :book_masters
18
- resources :book_masters , except : %w[ new ] do
21
+ resources :book_masters , except : %w[ import ] do
19
22
collection { post :bulk_insert }
20
23
end
21
24
resources :ndc_categories
You can’t perform that action at this time.
0 commit comments