質問編集履歴
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -131,3 +131,39 @@
|
|
131
131
|
database: db/production.sqlite3
|
132
132
|
|
133
133
|
```
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
[ここ](http://iteba.hateblo.jp/entry/2014/07/12/224544 )を参考に以下のように変更して見ましたが、
|
138
|
+
|
139
|
+
「could not connect to server: No such file or directory (PG::ConnectionBad)」と出ます。
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
```ここに言語を入力
|
146
|
+
|
147
|
+
def insert(all)
|
148
|
+
|
149
|
+
cur = File.expand_path(File.dirname(File.dirname(__FILE__)))
|
150
|
+
|
151
|
+
cur = cur + "/../rails_app/db/production.sqlite3"
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
db = PG::connect(cur)
|
156
|
+
|
157
|
+
all.each do |a|
|
158
|
+
|
159
|
+
title = a[:title]
|
160
|
+
|
161
|
+
url = a[:url]
|
162
|
+
|
163
|
+
image = a[:image]
|
164
|
+
|
165
|
+
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}')
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
```
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,21 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
+
↓rails insertフォルダ内のinsert.rb
|
24
|
+
|
25
|
+
|
26
|
+
|
23
27
|
```ここに言語を入力
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
:
|
32
|
+
|
33
|
+
:
|
34
|
+
|
35
|
+
:
|
36
|
+
|
37
|
+
:
|
24
38
|
|
25
39
|
def insert(all)
|
26
40
|
|
@@ -42,4 +56,78 @@
|
|
42
56
|
|
43
57
|
end
|
44
58
|
|
59
|
+
|
60
|
+
|
61
|
+
:
|
62
|
+
|
63
|
+
:
|
64
|
+
|
65
|
+
:
|
66
|
+
|
67
|
+
:
|
68
|
+
|
45
69
|
```
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
config/database.yml
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
```ここに言語を入力
|
78
|
+
|
79
|
+
# SQLite version 3.x
|
80
|
+
|
81
|
+
# gem install sqlite3
|
82
|
+
|
83
|
+
#
|
84
|
+
|
85
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
86
|
+
|
87
|
+
# gem 'sqlite3'
|
88
|
+
|
89
|
+
#
|
90
|
+
|
91
|
+
default: &default
|
92
|
+
|
93
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
94
|
+
|
95
|
+
timeout: 5000
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
development:
|
100
|
+
|
101
|
+
<<: *default
|
102
|
+
|
103
|
+
adapter: sqlite3
|
104
|
+
|
105
|
+
database: db/development.sqlite3
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
# Warning: The database defined as "test" will be erased and
|
110
|
+
|
111
|
+
# re-generated from your development database when you run "rake".
|
112
|
+
|
113
|
+
# Do not set this db to the same as development or production.
|
114
|
+
|
115
|
+
test:
|
116
|
+
|
117
|
+
<<: *default
|
118
|
+
|
119
|
+
adapter: sqlite3
|
120
|
+
|
121
|
+
database: db/test.sqlite3
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
production:
|
126
|
+
|
127
|
+
<<: *default
|
128
|
+
|
129
|
+
adapter: postgresql
|
130
|
+
|
131
|
+
database: db/production.sqlite3
|
132
|
+
|
133
|
+
```
|