質問編集履歴
2
ソースコード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
Started GET "/micropost/ql05NTxxxxx/edit" for 10.0.2.2 at 2017-02-15 02:36:34 +0000
|
23
23
|
Processing by MicropostController#edit as HTML
|
24
24
|
Parameters: {"access_token"=>"ql05NTxxxxx"}
|
25
|
-
|
25
|
+
Micropost Load (2.0ms) SELECT "micropost".* FROM "micropost" WHERE "micropost"."token" = ? LIMIT ? [["token", "ql05NTxxxxx"], ["LIMIT", 1]]
|
26
26
|
Rendering micropost/edit.html.erb within layouts/application
|
27
27
|
```
|
28
28
|
|
@@ -30,7 +30,7 @@
|
|
30
30
|
```
|
31
31
|
Started PATCH "/micropost/2" for 10.0.2.2 at 2017-02-15 02:36:43 +0000
|
32
32
|
Processing by MicropostController#update as HTML
|
33
|
-
Parameters: {"utf8"=>"✓", "authenticity_token"=>"wb8ni196rHHcoJdMYxDSg1DA==", "
|
33
|
+
Parameters: {"utf8"=>"✓", "authenticity_token"=>"wb8ni196rHHcoJdMYxDSg1DA==", "micropost"=>{"title"=>"テスト", "content"=>"この投稿はテストです\r\n\r\n追加しました", "status"=>"published"}, "commit"=>"登録", "token"=>"2"
|
34
34
|
```
|
35
35
|
|
36
36
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
@@ -46,10 +46,52 @@
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# Never trust parameters from the scary internet, only allow the white list through.
|
49
|
-
def
|
49
|
+
def micropost_params
|
50
50
|
params.require(:micropost).permit(:title, :content, :status)
|
51
51
|
end
|
52
52
|
```
|
53
53
|
|
54
|
+
new.html.erb, edit.html.erbは以下の通りになっております
|
55
|
+
```
|
56
|
+
<section>
|
57
|
+
<h2>フォーム</h2>
|
58
|
+
<%= render 'form', micropost: @micropost %>
|
59
|
+
</section>
|
60
|
+
```
|
61
|
+
|
62
|
+
_form.html.erb
|
63
|
+
```
|
64
|
+
<%= form_for(micropost) do |f| %>
|
65
|
+
<% if micropost.errors.any? %>
|
66
|
+
<div id="error_explanation">
|
67
|
+
<h2><%= pluralize(micropost.errors.count, "error") %> prohibited this micropost from being saved:</h2>
|
68
|
+
|
69
|
+
<ul>
|
70
|
+
<% micropost.errors.full_messages.each do |message| %>
|
71
|
+
<li><%= message %></li>
|
72
|
+
<% end %>
|
73
|
+
</ul>
|
74
|
+
</div>
|
75
|
+
<% end %>
|
76
|
+
|
77
|
+
<dl>
|
78
|
+
<dt><span class="default-pink">必須</span><strong>タイトル</strong></dt>
|
79
|
+
<dd>
|
80
|
+
<%= f.text_field :title %>
|
81
|
+
</dd>
|
82
|
+
<dt><span class="default-pink">必須</span><strong>本文</strong></dt>
|
83
|
+
<dd>
|
84
|
+
<%= f.text_area :content %>
|
85
|
+
</dd>
|
86
|
+
<dt><span class="default-pink">必須</span><strong>公開状態</strong></dt>
|
87
|
+
<dd class="select">
|
88
|
+
<%= f.select :status, [ ["公開", "published"], ['非公開', "unpublish"], ["下書き", "draft"] ], :selected => "published" %>
|
89
|
+
</dd>
|
90
|
+
</dl>
|
91
|
+
<%= f.submit "登録", class: "default-pink" %>
|
92
|
+
<% end %>
|
93
|
+
|
94
|
+
```
|
95
|
+
|
54
96
|
この問題を解決したく思います.
|
55
97
|
皆様のお知恵をお借りできればと思います.よろしくお願い致します.
|
1
エラー文の追記・Contollerのソースコード追記
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
rails5:scaffoldで
|
1
|
+
rails5:scaffoldでupdateした時のエラー
|
body
CHANGED
@@ -16,9 +16,40 @@
|
|
16
16
|
undefined method `update' for nil:NilClass
|
17
17
|
```
|
18
18
|
|
19
|
+
pryで見たときはこのようになっております.
|
20
|
+
編集画面へアクセス
|
21
|
+
```
|
22
|
+
Started GET "/micropost/ql05NTxxxxx/edit" for 10.0.2.2 at 2017-02-15 02:36:34 +0000
|
23
|
+
Processing by MicropostController#edit as HTML
|
24
|
+
Parameters: {"access_token"=>"ql05NTxxxxx"}
|
25
|
+
Information Load (2.0ms) SELECT "micropost".* FROM "micropost" WHERE "micropost"."token" = ? LIMIT ? [["token", "ql05NTxxxxx"], ["LIMIT", 1]]
|
26
|
+
Rendering micropost/edit.html.erb within layouts/application
|
27
|
+
```
|
28
|
+
|
29
|
+
submitした時
|
30
|
+
```
|
31
|
+
Started PATCH "/micropost/2" for 10.0.2.2 at 2017-02-15 02:36:43 +0000
|
32
|
+
Processing by MicropostController#update as HTML
|
33
|
+
Parameters: {"utf8"=>"✓", "authenticity_token"=>"wb8ni196rHHcoJdMYxDSg1DA==", "information"=>{"title"=>"テスト", "content"=>"この投稿はテストです\r\n\r\n追加しました", "status"=>"published"}, "commit"=>"登録", "token"=>"2"
|
34
|
+
```
|
35
|
+
|
19
36
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
20
37
|
Ruby 2.3.3
|
21
38
|
Ruby on Rails 5.0.0.1
|
22
39
|
|
40
|
+
Controllerにて以下のように設定しております
|
41
|
+
```
|
42
|
+
private
|
43
|
+
# Use callbacks to share common setup or constraints between actions.
|
44
|
+
def set_micropost
|
45
|
+
@micropost = Micropost.find_by( token: params[ :token ] )
|
46
|
+
end
|
47
|
+
|
48
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
49
|
+
def information_params
|
50
|
+
params.require(:micropost).permit(:title, :content, :status)
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
23
54
|
この問題を解決したく思います.
|
24
55
|
皆様のお知恵をお借りできればと思います.よろしくお願い致します.
|