質問編集履歴

8

余計な情報を書き込んだ為

2017/11/10 07:19

投稿

zendendo
zendendo

スコア43

test CHANGED
File without changes
test CHANGED
@@ -202,9 +202,9 @@
202
202
 
203
203
  @user = User.new(user_params)
204
204
 
205
- @user.build_account #Userの子要素であるベーシックインカムアカウントを関連付ける
205
+ @user.build_account #Userの子要素であるアカウントを関連付ける
206
-
206
+
207
- # ベーシックインカムアカウントテーブルのaccount_numberのカラムに代入する
207
+ # インカムアカウントテーブルのaccount_numberのカラムに代入する
208
208
 
209
209
  @user.account.account_number = SecureRandom.random_number(1000000000000)
210
210
 

7

追記の修正

2017/11/10 07:19

投稿

zendendo
zendendo

スコア43

test CHANGED
File without changes
test CHANGED
@@ -184,7 +184,7 @@
184
184
 
185
185
  def index
186
186
 
187
- @basic_income_account = BasicIncomeAccount.all
187
+ @account = Account.all
188
188
 
189
189
  end
190
190
 
@@ -202,7 +202,7 @@
202
202
 
203
203
  @user = User.new(user_params)
204
204
 
205
- @user.build_basic_income_account #Userの子要素であるベーシックインカムアカウントを関連付ける
205
+ @user.build_account #Userの子要素であるベーシックインカムアカウントを関連付ける
206
206
 
207
207
  # ベーシックインカムアカウントテーブルのaccount_numberのカラムに代入する
208
208
 
@@ -228,7 +228,7 @@
228
228
 
229
229
 
230
230
 
231
- def basic_income_params
231
+ def account_params
232
232
 
233
233
  params.require(:account).permit(:account_number, :balance)
234
234
 
@@ -274,7 +274,7 @@
274
274
 
275
275
  ```ここに言語を入力
276
276
 
277
- Megterra::Application.routes.draw do
277
+ Rails.Application.routes.draw do
278
278
 
279
279
  ・・・
280
280
 

6

追記内容の修正

2017/11/03 05:50

投稿

zendendo
zendendo

スコア43

test CHANGED
File without changes
test CHANGED
@@ -130,7 +130,9 @@
130
130
 
131
131
 
132
132
 
133
- ###アドバイスを参考に変更したファイル内容を追記
133
+ ###アドバイスを参考に変更したファイル内容を追記(成功)
134
+
135
+ 以下には、アドバイスを参考にコードを修正し、最終的に成功したコード内容を追記しておきます。
134
136
 
135
137
 
136
138
 

5

追記の修正

2017/11/03 02:38

投稿

zendendo
zendendo

スコア43

test CHANGED
File without changes
test CHANGED
@@ -130,7 +130,7 @@
130
130
 
131
131
 
132
132
 
133
- ###アドバイスを受け追記(未解決)
133
+ ###アドバイスを参考に変更したファイル内容を追記
134
134
 
135
135
 
136
136
 
@@ -176,8 +176,20 @@
176
176
 
177
177
  class HogesController < ApplicationController
178
178
 
179
+
180
+
181
+
182
+
179
183
  def index
180
184
 
185
+ @basic_income_account = BasicIncomeAccount.all
186
+
187
+ end
188
+
189
+
190
+
191
+ def new
192
+
181
193
  @user = User.new
182
194
 
183
195
  end
@@ -188,7 +200,9 @@
188
200
 
189
201
  @user = User.new(user_params)
190
202
 
191
- @user.build_account
203
+ @user.build_basic_income_account #Userの子要素であるベーシックインカムアカウントを関連付ける
204
+
205
+ # ベーシックインカムアカウントテーブルのaccount_numberのカラムに代入する
192
206
 
193
207
  @user.account.account_number = SecureRandom.random_number(1000000000000)
194
208
 
@@ -196,6 +210,8 @@
196
210
 
197
211
  @user.save
198
212
 
213
+ redirect_to '/hoges/index'
214
+
199
215
  end
200
216
 
201
217
 
@@ -210,6 +226,12 @@
210
226
 
211
227
 
212
228
 
229
+ def basic_income_params
230
+
231
+ params.require(:account).permit(:account_number, :balance)
232
+
233
+ end
234
+
213
235
  end
214
236
 
215
237
  ```
@@ -220,6 +242,8 @@
220
242
 
221
243
  <p>index.html.erb</p>
222
244
 
245
+ <p>作成画面</p>
246
+
223
247
 
224
248
 
225
249
  <%= form_for(@user) do |f| %>
@@ -236,14 +260,12 @@
236
260
 
237
261
  <%= f.password_field :password %>
238
262
 
239
- <%= f.submit "登録" %>
263
+ <%= f.submit "会員登録" %>
240
264
 
241
265
  <% end %>
242
266
 
243
267
  </div>
244
268
 
245
-
246
-
247
269
  ```
248
270
 
249
271
  routes.rbに追記する。
@@ -256,7 +278,9 @@
256
278
 
257
279
  get 'hoges/index'
258
280
 
281
+ get 'hoges/new'
282
+
259
- post 'hoges' => 'hoges#create'
283
+ post 'users' => 'hoges#create'
260
284
 
261
285
  ・・・
262
286
 

4

誤字

2017/11/03 02:12

投稿

zendendo
zendendo

スコア43

test CHANGED
File without changes
test CHANGED
@@ -190,7 +190,7 @@
190
190
 
191
191
  @user.build_account
192
192
 
193
- @user.account_number = SecureRandom.random_number(1000000000000)
193
+ @user.account.account_number = SecureRandom.random_number(1000000000000)
194
194
 
195
195
  @user.account.balance = 0
196
196
 

3

誤字

2017/11/02 11:50

投稿

zendendo
zendendo

スコア43

test CHANGED
File without changes
test CHANGED
@@ -218,9 +218,7 @@
218
218
 
219
219
  ```ここに言語を入力
220
220
 
221
- <p>hoge.html.erb</p>
221
+ <p>index.html.erb</p>
222
-
223
- <p>BI口座作成画面</p>
224
222
 
225
223
 
226
224
 

2

アドバイスを参考にしたコードを追記

2017/11/02 07:47

投稿

zendendo
zendendo

スコア43

test CHANGED
File without changes
test CHANGED
@@ -127,3 +127,141 @@
127
127
  ruby 2.4.1
128
128
 
129
129
  devise (4.3.0)
130
+
131
+
132
+
133
+ ###アドバイスを受け追記(未解決)
134
+
135
+
136
+
137
+ model.user.rbを編集。
138
+
139
+ ```ここに言語を入力
140
+
141
+ class User < ApplicationRecord
142
+
143
+ has_one :account
144
+
145
+
146
+
147
+ # Include default devise modules. Others available are:
148
+
149
+ # :confirmable, :lockable, :timeoutable and :omniauthable
150
+
151
+ devise :database_authenticatable, :registerable,
152
+
153
+ :recoverable, :rememberable, :trackable, :validatable
154
+
155
+ end
156
+
157
+ ```
158
+
159
+ model/account.rbを編集。
160
+
161
+ ```ここに言語を入力
162
+
163
+ class Account < ApplicationRecord
164
+
165
+ belongs_to :user
166
+
167
+ end
168
+
169
+
170
+
171
+ ```
172
+
173
+ app/controllersにhoges_controller.rbを作成して編集。
174
+
175
+ ```ここに言語を入力
176
+
177
+ class HogesController < ApplicationController
178
+
179
+ def index
180
+
181
+ @user = User.new
182
+
183
+ end
184
+
185
+
186
+
187
+ def create
188
+
189
+ @user = User.new(user_params)
190
+
191
+ @user.build_account
192
+
193
+ @user.account_number = SecureRandom.random_number(1000000000000)
194
+
195
+ @user.account.balance = 0
196
+
197
+ @user.save
198
+
199
+ end
200
+
201
+
202
+
203
+ private
204
+
205
+ def user_params
206
+
207
+ params.require(:user).permit(:password, :email)
208
+
209
+ end
210
+
211
+
212
+
213
+ end
214
+
215
+ ```
216
+
217
+ /app/views/hogeにindex.html.erbを作成して編集。
218
+
219
+ ```ここに言語を入力
220
+
221
+ <p>hoge.html.erb</p>
222
+
223
+ <p>BI口座作成画面</p>
224
+
225
+
226
+
227
+ <%= form_for(@user) do |f| %>
228
+
229
+
230
+
231
+ <div class= "field">
232
+
233
+ <%= f.label :email %>
234
+
235
+ <%= f.email_field :email %>
236
+
237
+ <%= f.label :password %>
238
+
239
+ <%= f.password_field :password %>
240
+
241
+ <%= f.submit "登録" %>
242
+
243
+ <% end %>
244
+
245
+ </div>
246
+
247
+
248
+
249
+ ```
250
+
251
+ routes.rbに追記する。
252
+
253
+ ```ここに言語を入力
254
+
255
+ Megterra::Application.routes.draw do
256
+
257
+ ・・・
258
+
259
+ get 'hoges/index'
260
+
261
+ post 'hoges' => 'hoges#create'
262
+
263
+ ・・・
264
+
265
+ end
266
+
267
+ ```

1

タイトル変更

2017/11/02 07:13

投稿

zendendo
zendendo

スコア43

test CHANGED
@@ -1 +1 @@
1
- railsでユーザー(devise)と1:1の関係にあるテーブルを新規会員登録と同時に自動作成したい
1
+ railsでユーザー新規登録(devise)をしたき1:1の関係にある他のテーブルにデータを自動作成したい
test CHANGED
File without changes