質問編集履歴

2

誤字

2020/02/24 08:04

投稿

matsubishi5
matsubishi5

スコア7

test CHANGED
@@ -1 +1 @@
1
- 【Rails】render indexを実行すると、「NoMethodError」が出てしまう
1
+ 【Rails】'render new'を実行すると、「ArgumentError」が出
test CHANGED
@@ -1,6 +1,8 @@
1
1
  ### 発生している問題・エラーメッセージ
2
2
 
3
- ![イメージ説明](07ddea6bea243fc4d8c2398e142f75bc.png)
3
+ ![イメージ説明](069cba69089dda18c927434aaa110e3e.png)
4
+
5
+ ![イメージ説明](712de7d84fba5892a1be40d5d1eda14b.png)
4
6
 
5
7
  ### 該当のソースコード
6
8
 
@@ -58,11 +60,11 @@
58
60
 
59
61
  def new
60
62
 
61
- book = Book.new
63
+ @book = Book.new
62
-
64
+
63
- end
65
+ end
64
-
65
-
66
+
67
+
66
68
 
67
69
  def create
68
70
 
@@ -76,7 +78,7 @@
76
78
 
77
79
  else
78
80
 
79
- render 'index'
81
+ render 'new'
80
82
 
81
83
  end
82
84
 
@@ -88,8 +90,6 @@
88
90
 
89
91
  @books = Book.all
90
92
 
91
- @book = Book.new
92
-
93
93
  end
94
94
 
95
95
 
@@ -114,11 +114,15 @@
114
114
 
115
115
  book = Book.find(params[:id])
116
116
 
117
- book.update(book_params)
117
+ if book.update(book_params)
118
-
118
+
119
- redirect_to todolist_path(book)
119
+ redirect_to todolist_path(book)
120
-
120
+
121
- flash[:notice] = "Book was successfully updated."
121
+ flash[:notice] = "Book was successfully updated."
122
+
123
+ else
124
+
125
+ render 'edit'
122
126
 
123
127
  end
124
128
 
@@ -148,57 +152,9 @@
148
152
 
149
153
  ```
150
154
 
151
- **app/views/todolists/index.html.erb**
155
+ **app/views/todolists/new.html.erb**
152
-
156
+
153
- ```Ruby
157
+ ```Ruby
154
-
155
- <h1>Books</h1>
156
-
157
-
158
-
159
- <table>
160
-
161
- <thead>
162
-
163
- <tr>
164
-
165
- <th>title</th>
166
-
167
- <th>body</th>
168
-
169
- </tr>
170
-
171
- </thead>
172
-
173
-
174
-
175
- <tbody>
176
-
177
- <% @books.each do |book| %>
178
-
179
- <tr>
180
-
181
- <td><p><%= book.title %></p></td>
182
-
183
- <td><p><%= book.body %></p></td>
184
-
185
-
186
-
187
- <td><%= link_to "Show",todolist_path(book) %></td>
188
-
189
- <td><%= link_to "Edit",edit_todolist_path(book) %></td>
190
-
191
- <td><%= link_to "Destroy",destroy_todolist_path(book),method: :delete,'data-confirm' => 'Are you sure?' %></td>
192
-
193
- </tr>
194
-
195
- <% end %>
196
-
197
- </tbody>
198
-
199
- </table>
200
-
201
-
202
158
 
203
159
  <h2>New Book</h2>
204
160
 

1

誤字

2020/02/24 08:04

投稿

matsubishi5
matsubishi5

スコア7

test CHANGED
File without changes
test CHANGED
@@ -266,4 +266,4 @@
266
266
 
267
267
  Ruby on Railsで、「本の感想を投稿できるサイト」という名目の簡易投稿サイトを作成中です。
268
268
 
269
- タイトル又は本文が空白であった場合にエラーメッセージを表示させようとしたところ、上記のエラーが発生してしまいました。
269
+ 新規投稿時、タイトル又は本文が空白であった場合にエラーメッセージを表示させようとしたところ、上記のエラーが発生してしまいました。