質問編集履歴
1
コントローラーのコードとエラー画面を追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -81,4 +81,51 @@
|
|
81
81
|
<% end %>
|
82
82
|
</div>
|
83
83
|
</div>
|
84
|
-
```
|
84
|
+
```
|
85
|
+
|
86
|
+
infos_controller.rb
|
87
|
+
```
|
88
|
+
class InfosController < ApplicationController
|
89
|
+
|
90
|
+
def new
|
91
|
+
@info = Info.new
|
92
|
+
end
|
93
|
+
|
94
|
+
def create
|
95
|
+
@info = Info.new(info_params)
|
96
|
+
if @info.save
|
97
|
+
flash[:success] = '更新しました。'
|
98
|
+
redirect_to edit_info_url
|
99
|
+
else
|
100
|
+
flash.now[:danger] = '更新できませんでした。'
|
101
|
+
render :edit
|
102
|
+
end
|
103
|
+
current_user.info = @info
|
104
|
+
end
|
105
|
+
|
106
|
+
def edit
|
107
|
+
@info = current_user.info
|
108
|
+
end
|
109
|
+
|
110
|
+
def update
|
111
|
+
@info = Info.find_by(user_id: params[:id])
|
112
|
+
if @info.update(info_params)
|
113
|
+
flash[:success] = '更新しました。'
|
114
|
+
redirect_to edit_info_url
|
115
|
+
else
|
116
|
+
flash.now[:danger] = '更新できませんでした。'
|
117
|
+
render :edit
|
118
|
+
end
|
119
|
+
current_user.info = @info
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def info_params
|
126
|
+
params.require(:info).permit(:name, :collage, :department, :sex, :location, :avatar)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
```
|
130
|
+
|
131
|
+

|