質問編集履歴
7
model
title
CHANGED
File without changes
|
body
CHANGED
@@ -74,15 +74,15 @@
|
|
74
74
|
header = spreadsheet.row(1)
|
75
75
|
(2..spreadsheet.last_row).each do |i|
|
76
76
|
row = Hash[[header, spreadsheet.row(i)].transpose]
|
77
|
-
|
77
|
+
btob_quotation = find_by_id(row["id"]) || new
|
78
|
-
|
78
|
+
btob_quotation.attributes = row.to_hash.slice(*accessible_attributes)
|
79
|
-
|
79
|
+
btob_quotation.save!
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
def self.open_spreadsheet(file)
|
84
84
|
case File.extname(file.original_filename)
|
85
|
-
when ".csv" then
|
85
|
+
when ".csv" then CSV.new(file.path, nil)
|
86
86
|
else raise "Unknown file type: #{file.original_filename}"
|
87
87
|
end
|
88
88
|
end
|
6
.
title
CHANGED
File without changes
|
body
CHANGED
@@ -88,9 +88,8 @@
|
|
88
88
|
end
|
89
89
|
```
|
90
90
|
|
91
|
-
###
|
91
|
+
### 参考にしているサイト
|
92
92
|
|
93
|
-
参考にしているサイト
|
94
93
|
[#396 Importing CSV and Excel – RailsCasts](http://railscasts.com/episodes/396-importing-csv-and-excel?autoplay=true)
|
95
94
|
|
96
95
|
### 補足情報(FW/ツールのバージョンなど)
|
5
im
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,7 +11,9 @@
|
|
11
11
|
uninitialized constant BtobQuotation::Csv
|
12
12
|
```
|
13
13
|
エラー画面キャプチャ
|
14
|
-

|
15
|
+

|
16
|
+

|
15
17
|
|
16
18
|
CSVファイルをアップロードした際のログ
|
17
19
|
```
|
4
log
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,6 +13,27 @@
|
|
13
13
|
エラー画面キャプチャ
|
14
14
|

|
15
15
|
|
16
|
+
CSVファイルをアップロードした際のログ
|
17
|
+
```
|
18
|
+
I, [2019-07-17T18:26:15.712452 #9546] INFO -- : Started POST "/btob_quotations/import" for 192.168.11.30 at 2019-07-17 18:26:15 +0900
|
19
|
+
I, [2019-07-17T18:26:15.714922 #9546] INFO -- : Cannot render console from 192.168.11.30! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
|
20
|
+
I, [2019-07-17T18:26:15.771705 #9546] INFO -- : Processing by BtobQuotationsController#import as HTML
|
21
|
+
I, [2019-07-17T18:26:15.772242 #9546] INFO -- : Parameters: {"utf8"=>"✓", "authenticity_token"=>"7PtnpymZqYBn4UOP7OTDiVCi6ZhKZ0WZ8UhM8lzk/DPUqdXybcW6bN+tq/8AatqqK6yK+eUGrk8Qj20wKRd2jA==", "file"=>#<ActionDispatch::Http::UploadedFile:0x00007f433e909f10 @tempfile=#<Tempfile:/tmp/RackMultipart20190717-9546-1tgkswu.csv>, @original_filename="btob_quotations (2).csv", @content_type="application/vnd.ms-excel", @headers="Content-Disposition: form-data; name=\"file\"; filename=\"btob_quotations (2).csv\"\r\nContent-Type: application/vnd.ms-excel\r\n">, "commit"=>"オブジェクトを一括インポート"}
|
22
|
+
D, [2019-07-17T18:26:15.774000 #9546] DEBUG -- : ActiveRecord::SessionStore::Session Load (0.4ms) SELECT `sessions`.* FROM `sessions` WHERE `sessions`.`session_id` = 'cf79cf20b72b18e45fb13cb190223dc2' ORDER BY `sessions`.`id` ASC LIMIT 1
|
23
|
+
I, [2019-07-17T18:26:15.786085 #9546] INFO -- : Completed 500 Internal Server Error in 13ms (ActiveRecord: 0.4ms)
|
24
|
+
|
25
|
+
|
26
|
+
F, [2019-07-17T18:26:15.825356 #9546] FATAL -- :
|
27
|
+
NameError - uninitialized constant BtobQuotation::Csv:
|
28
|
+
app/models/btob_quotation.rb:34:in `open_spreadsheet'
|
29
|
+
app/models/btob_quotation.rb:22:in `import'
|
30
|
+
app/controllers/btob_quotations_controller.rb:86:in `import'
|
31
|
+
|
32
|
+
I, [2019-07-17T18:26:15.928236 #9546] INFO -- : Started POST "/__better_errors/5de3351b5bd4fa51/variables" for 192.168.11.30 at 2019-07-17 18:26:15 +0900
|
33
|
+
I, [2019-07-17T18:26:15.929145 #9546] INFO -- : Cannot render console from 192.168.11.30! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
|
34
|
+
|
35
|
+
```
|
36
|
+
|
16
37
|
### 該当のソースコード
|
17
38
|
|
18
39
|
btob_quotations\index.html.erb
|
3
あ
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Ruby on RailsでCSVファイルインポート
|
1
|
+
Ruby on RailsでCSVファイルインポートがエラーになる。
|
body
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
3
|
タブ区切りCSVファイルからのインポートがうまくいかない。
|
4
|
+
CSVファイルをアップロードすると下記のエラーになる。
|
4
5
|
検索しても情報が少なく、自力で解決できそうにない。
|
5
6
|
|
6
7
|
### 発生している問題・エラーメッセージ
|
2
.
title
CHANGED
File without changes
|
body
CHANGED
@@ -45,7 +45,7 @@
|
|
45
45
|
|
46
46
|
models\btob_quotation.rb
|
47
47
|
```
|
48
|
-
def self.import(file)
|
48
|
+
def self.import(file)
|
49
49
|
spreadsheet = open_spreadsheet(file)
|
50
50
|
header = spreadsheet.row(1)
|
51
51
|
(2..spreadsheet.last_row).each do |i|
|
1
あ
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
CSVファイルからのインポートがうまくいかない。
|
3
|
+
タブ区切りCSVファイルからのインポートがうまくいかない。
|
4
4
|
検索しても情報が少なく、自力で解決できそうにない。
|
5
5
|
|
6
6
|
### 発生している問題・エラーメッセージ
|