質問するログイン新規登録

質問編集履歴

7

model

2019/07/22 08:46

投稿

gs13
gs13

スコア15

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
- product = find_by_id(row["id"]) || new
77
+ btob_quotation = find_by_id(row["id"]) || new
78
- product.attributes = row.to_hash.slice(*accessible_attributes)
78
+ btob_quotation.attributes = row.to_hash.slice(*accessible_attributes)
79
- product.save!
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 Csv.new(file.path, nil, :ignore)
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

.

2019/07/22 08:46

投稿

gs13
gs13

スコア15

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

2019/07/22 07:51

投稿

gs13
gs13

スコア15

title CHANGED
File without changes
body CHANGED
@@ -11,7 +11,9 @@
11
11
  uninitialized constant BtobQuotation::Csv
12
12
  ```
13
13
  エラー画面キャプチャ
14
- ![イメージ説明](2278aaa009969b05d8405e3d01dd6d40.png)
14
+ ![イメージ説明](40b0ca0abc0d113b4c6e5b3b3fade122.png)
15
+ ![イメージ説明](5273177b8d9ed1d00c42aab3da3953ff.png)
16
+ ![イメージ説明](5090853f50a90391d057f522f89391fa.png)
15
17
 
16
18
  CSVファイルをアップロードした際のログ
17
19
  ```

4

log

2019/07/17 09:34

投稿

gs13
gs13

スコア15

title CHANGED
File without changes
body CHANGED
@@ -13,6 +13,27 @@
13
13
  エラー画面キャプチャ
14
14
  ![イメージ説明](2278aaa009969b05d8405e3d01dd6d40.png)
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

2019/07/17 09:27

投稿

gs13
gs13

スコア15

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

.

2019/07/17 09:25

投稿

gs13
gs13

スコア15

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

2019/07/17 09:24

投稿

gs13
gs13

スコア15

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
  ### 発生している問題・エラーメッセージ