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

質問編集履歴

2

追記

2018/03/31 02:40

投稿

renren643
renren643

スコア279

title CHANGED
File without changes
body CHANGED
@@ -64,4 +64,22 @@
64
64
  <<: *default
65
65
  adapter: postgresql
66
66
  database: db/production.sqlite3
67
+ ```
68
+
69
+ [ここ](http://iteba.hateblo.jp/entry/2014/07/12/224544 )を参考に以下のように変更して見ましたが、
70
+ 「could not connect to server: No such file or directory (PG::ConnectionBad)」と出ます。
71
+
72
+
73
+ ```ここに言語を入力
74
+ def insert(all)
75
+ cur = File.expand_path(File.dirname(File.dirname(__FILE__)))
76
+ cur = cur + "/../rails_app/db/production.sqlite3"
77
+
78
+ db = PG::connect(cur)
79
+ all.each do |a|
80
+ title = a[:title]
81
+ url = a[:url]
82
+ image = a[:image]
83
+ db.exec('insert into articles (title,url,created_at,updated_at,image) values (?,?,?,?,?)', '#{title}','#{url}','2018-03-22 21:00:00','2018-03-22 21:00:00','#{image}')
84
+ end
67
85
  ```

1

追記

2018/03/31 02:40

投稿

renren643
renren643

スコア279

title CHANGED
File without changes
body CHANGED
@@ -9,7 +9,14 @@
9
9
  ちなみにherokuで運用しており、DBはpostgresqlです。
10
10
 
11
11
 
12
+ ↓rails insertフォルダ内のinsert.rb
13
+
12
14
  ```ここに言語を入力
15
+
16
+
17
+
18
+
19
+
13
20
  def insert(all)
14
21
  cur = File.expand_path(File.dirname(File.dirname(__FILE__)))
15
22
  cur = cur + "/../rails_app/db/development.sqlite3"
@@ -20,4 +27,41 @@
20
27
      image = a[:image]
21
28
  db.execute('insert into articles ("title" ,"url","created_at","updated_at","image") values (?,?,?,?,?)', "#{title}","#{url}",'2018-03-22 21:00:00','2018-03-22 21:00:00',"#{image}")
22
29
  end
30
+
31
+
32
+
33
+
34
+
35
+ ```
36
+
37
+ config/database.yml
38
+
39
+ ```ここに言語を入力
40
+ # SQLite version 3.x
41
+ # gem install sqlite3
42
+ #
43
+ # Ensure the SQLite 3 gem is defined in your Gemfile
44
+ # gem 'sqlite3'
45
+ #
46
+ default: &default
47
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
48
+ timeout: 5000
49
+
50
+ development:
51
+ <<: *default
52
+ adapter: sqlite3
53
+ database: db/development.sqlite3
54
+
55
+ # Warning: The database defined as "test" will be erased and
56
+ # re-generated from your development database when you run "rake".
57
+ # Do not set this db to the same as development or production.
58
+ test:
59
+ <<: *default
60
+ adapter: sqlite3
61
+ database: db/test.sqlite3
62
+
63
+ production:
64
+ <<: *default
65
+ adapter: postgresql
66
+ database: db/production.sqlite3
23
67
  ```