質問編集履歴
8
余計な情報を書き込んだ為
title
CHANGED
File without changes
|
body
CHANGED
@@ -100,8 +100,8 @@
|
|
100
100
|
|
101
101
|
def create
|
102
102
|
@user = User.new(user_params)
|
103
|
-
@user.build_account #Userの子要素である
|
103
|
+
@user.build_account #Userの子要素であるアカウントを関連付ける
|
104
|
-
#
|
104
|
+
# インカムアカウントテーブルのaccount_numberのカラムに代入する
|
105
105
|
@user.account.account_number = SecureRandom.random_number(1000000000000)
|
106
106
|
@user.account.balance = 0
|
107
107
|
@user.save
|
7
追記の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -91,7 +91,7 @@
|
|
91
91
|
|
92
92
|
|
93
93
|
def index
|
94
|
-
@
|
94
|
+
@account = Account.all
|
95
95
|
end
|
96
96
|
|
97
97
|
def new
|
@@ -100,7 +100,7 @@
|
|
100
100
|
|
101
101
|
def create
|
102
102
|
@user = User.new(user_params)
|
103
|
-
@user.
|
103
|
+
@user.build_account #Userの子要素であるベーシックインカムアカウントを関連付ける
|
104
104
|
# ベーシックインカムアカウントテーブルのaccount_numberのカラムに代入する
|
105
105
|
@user.account.account_number = SecureRandom.random_number(1000000000000)
|
106
106
|
@user.account.balance = 0
|
@@ -113,7 +113,7 @@
|
|
113
113
|
params.require(:user).permit(:password, :email)
|
114
114
|
end
|
115
115
|
|
116
|
-
def
|
116
|
+
def account_params
|
117
117
|
params.require(:account).permit(:account_number, :balance)
|
118
118
|
end
|
119
119
|
end
|
@@ -136,7 +136,7 @@
|
|
136
136
|
```
|
137
137
|
routes.rbに追記する。
|
138
138
|
```ここに言語を入力
|
139
|
-
|
139
|
+
Rails.Application.routes.draw do
|
140
140
|
・・・
|
141
141
|
get 'hoges/index'
|
142
142
|
get 'hoges/new'
|
6
追記内容の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -64,7 +64,8 @@
|
|
64
64
|
ruby 2.4.1
|
65
65
|
devise (4.3.0)
|
66
66
|
|
67
|
-
###アドバイスを参考に変更したファイル内容を追記
|
67
|
+
###アドバイスを参考に変更したファイル内容を追記(成功)
|
68
|
+
以下には、アドバイスを参考にコードを修正し、最終的に成功したコード内容を追記しておきます。
|
68
69
|
|
69
70
|
model.user.rbを編集。
|
70
71
|
```ここに言語を入力
|
5
追記の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -64,7 +64,7 @@
|
|
64
64
|
ruby 2.4.1
|
65
65
|
devise (4.3.0)
|
66
66
|
|
67
|
-
###アドバイスを
|
67
|
+
###アドバイスを参考に変更したファイル内容を追記
|
68
68
|
|
69
69
|
model.user.rbを編集。
|
70
70
|
```ここに言語を入力
|
@@ -87,16 +87,24 @@
|
|
87
87
|
app/controllersにhoges_controller.rbを作成して編集。
|
88
88
|
```ここに言語を入力
|
89
89
|
class HogesController < ApplicationController
|
90
|
+
|
91
|
+
|
90
92
|
def index
|
93
|
+
@basic_income_account = BasicIncomeAccount.all
|
94
|
+
end
|
95
|
+
|
96
|
+
def new
|
91
97
|
@user = User.new
|
92
98
|
end
|
93
99
|
|
94
100
|
def create
|
95
101
|
@user = User.new(user_params)
|
96
|
-
@user.
|
102
|
+
@user.build_basic_income_account #Userの子要素であるベーシックインカムアカウントを関連付ける
|
103
|
+
# ベーシックインカムアカウントテーブルのaccount_numberのカラムに代入する
|
97
104
|
@user.account.account_number = SecureRandom.random_number(1000000000000)
|
98
105
|
@user.account.balance = 0
|
99
106
|
@user.save
|
107
|
+
redirect_to '/hoges/index'
|
100
108
|
end
|
101
109
|
|
102
110
|
private
|
@@ -104,11 +112,15 @@
|
|
104
112
|
params.require(:user).permit(:password, :email)
|
105
113
|
end
|
106
114
|
|
115
|
+
def basic_income_params
|
116
|
+
params.require(:account).permit(:account_number, :balance)
|
117
|
+
end
|
107
118
|
end
|
108
119
|
```
|
109
120
|
/app/views/hogeにindex.html.erbを作成して編集。
|
110
121
|
```ここに言語を入力
|
111
122
|
<p>index.html.erb</p>
|
123
|
+
<p>作成画面</p>
|
112
124
|
|
113
125
|
<%= form_for(@user) do |f| %>
|
114
126
|
|
@@ -117,17 +129,17 @@
|
|
117
129
|
<%= f.email_field :email %>
|
118
130
|
<%= f.label :password %>
|
119
131
|
<%= f.password_field :password %>
|
120
|
-
<%= f.submit "登録" %>
|
132
|
+
<%= f.submit "会員登録" %>
|
121
133
|
<% end %>
|
122
134
|
</div>
|
123
|
-
|
124
135
|
```
|
125
136
|
routes.rbに追記する。
|
126
137
|
```ここに言語を入力
|
127
138
|
Megterra::Application.routes.draw do
|
128
139
|
・・・
|
129
140
|
get 'hoges/index'
|
141
|
+
get 'hoges/new'
|
130
|
-
post '
|
142
|
+
post 'users' => 'hoges#create'
|
131
143
|
・・・
|
132
144
|
end
|
133
145
|
```
|
4
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -94,7 +94,7 @@
|
|
94
94
|
def create
|
95
95
|
@user = User.new(user_params)
|
96
96
|
@user.build_account
|
97
|
-
@user.account_number = SecureRandom.random_number(1000000000000)
|
97
|
+
@user.account.account_number = SecureRandom.random_number(1000000000000)
|
98
98
|
@user.account.balance = 0
|
99
99
|
@user.save
|
100
100
|
end
|
3
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -108,8 +108,7 @@
|
|
108
108
|
```
|
109
109
|
/app/views/hogeにindex.html.erbを作成して編集。
|
110
110
|
```ここに言語を入力
|
111
|
-
<p>
|
111
|
+
<p>index.html.erb</p>
|
112
|
-
<p>BI口座作成画面</p>
|
113
112
|
|
114
113
|
<%= form_for(@user) do |f| %>
|
115
114
|
|
2
アドバイスを参考にしたコードを追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -62,4 +62,73 @@
|
|
62
62
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
63
63
|
Rails 5.1.3
|
64
64
|
ruby 2.4.1
|
65
|
-
devise (4.3.0)
|
65
|
+
devise (4.3.0)
|
66
|
+
|
67
|
+
###アドバイスを受け追記(未解決)
|
68
|
+
|
69
|
+
model.user.rbを編集。
|
70
|
+
```ここに言語を入力
|
71
|
+
class User < ApplicationRecord
|
72
|
+
has_one :account
|
73
|
+
|
74
|
+
# Include default devise modules. Others available are:
|
75
|
+
# :confirmable, :lockable, :timeoutable and :omniauthable
|
76
|
+
devise :database_authenticatable, :registerable,
|
77
|
+
:recoverable, :rememberable, :trackable, :validatable
|
78
|
+
end
|
79
|
+
```
|
80
|
+
model/account.rbを編集。
|
81
|
+
```ここに言語を入力
|
82
|
+
class Account < ApplicationRecord
|
83
|
+
belongs_to :user
|
84
|
+
end
|
85
|
+
|
86
|
+
```
|
87
|
+
app/controllersにhoges_controller.rbを作成して編集。
|
88
|
+
```ここに言語を入力
|
89
|
+
class HogesController < ApplicationController
|
90
|
+
def index
|
91
|
+
@user = User.new
|
92
|
+
end
|
93
|
+
|
94
|
+
def create
|
95
|
+
@user = User.new(user_params)
|
96
|
+
@user.build_account
|
97
|
+
@user.account_number = SecureRandom.random_number(1000000000000)
|
98
|
+
@user.account.balance = 0
|
99
|
+
@user.save
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
def user_params
|
104
|
+
params.require(:user).permit(:password, :email)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
```
|
109
|
+
/app/views/hogeにindex.html.erbを作成して編集。
|
110
|
+
```ここに言語を入力
|
111
|
+
<p>hoge.html.erb</p>
|
112
|
+
<p>BI口座作成画面</p>
|
113
|
+
|
114
|
+
<%= form_for(@user) do |f| %>
|
115
|
+
|
116
|
+
<div class= "field">
|
117
|
+
<%= f.label :email %>
|
118
|
+
<%= f.email_field :email %>
|
119
|
+
<%= f.label :password %>
|
120
|
+
<%= f.password_field :password %>
|
121
|
+
<%= f.submit "登録" %>
|
122
|
+
<% end %>
|
123
|
+
</div>
|
124
|
+
|
125
|
+
```
|
126
|
+
routes.rbに追記する。
|
127
|
+
```ここに言語を入力
|
128
|
+
Megterra::Application.routes.draw do
|
129
|
+
・・・
|
130
|
+
get 'hoges/index'
|
131
|
+
post 'hoges' => 'hoges#create'
|
132
|
+
・・・
|
133
|
+
end
|
134
|
+
```
|
1
タイトル変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
railsでユーザー(devise)と
|
1
|
+
railsでユーザー新規登録(devise)をしたとき1:1の関係にある他のテーブルにデータを自動作成したい
|
body
CHANGED
File without changes
|