質問編集履歴

6

エラー

2016/04/17 05:47

投稿

mig2332
mig2332

スコア33

test CHANGED
File without changes
test CHANGED
@@ -286,6 +286,10 @@
286
286
 
287
287
  ```
288
288
 
289
+ ActiveRecord::RecordNotFound in NotesController#rule
290
+
291
+
292
+
289
293
  Couldn't find Note with 'id'=
290
294
 
291
295
 

5

試したことの追加

2016/04/17 05:47

投稿

mig2332
mig2332

スコア33

test CHANGED
@@ -1 +1 @@
1
- Scaffoldresources追加した際のエラー
1
+ Scaffoldで作成したresourcesにcollection doを追加した際のエラー
test CHANGED
@@ -22,9 +22,9 @@
22
22
 
23
23
 
24
24
 
25
- そもそもscaffoldで作成されたnotesに新しいルーティングは追加することはできますか?
25
+
26
-
26
+
27
- 全くの初心者です。
27
+ 初心者です。
28
28
 
29
29
 
30
30
 
@@ -274,6 +274,52 @@
274
274
 
275
275
 
276
276
 
277
+ ###試してみたこと
278
+
279
+ collection doかmember doをルーティングに使ってみるという回答をいただきたcollection doを使用しました。
280
+
281
+
282
+
283
+ するとhttp://localhost:3000/notes/ruleでエラーが
284
+
285
+
286
+
287
+ ```
288
+
289
+ Couldn't find Note with 'id'=
290
+
291
+
292
+
293
+ def set_note
294
+
295
+ @note = Note.find(params[:id])
296
+
297
+ end
298
+
299
+ ```
300
+
301
+
302
+
303
+ $rake routes
304
+
305
+ rule_notes GET /notes/rule(.:format) notes#rule
306
+
307
+
308
+
309
+
310
+
311
+ に変わりました。
312
+
313
+
314
+
315
+ :idを含むmember do ではエラーなくruleが表示されました。
316
+
317
+ collection doを使用したいのですが、エラーが表示されます。
318
+
319
+
320
+
321
+
322
+
277
323
  ###補足情報(言語/FW/ツール等のバージョンなど)
278
324
 
279
325
  Ruby on Rails

4

追記

2016/04/17 05:37

投稿

mig2332
mig2332

スコア33

test CHANGED
File without changes
test CHANGED
@@ -22,6 +22,10 @@
22
22
 
23
23
 
24
24
 
25
+ そもそもscaffoldで作成されたnotesに新しいルーティングは追加することはできますか?
26
+
27
+ 全くの初心者です。
28
+
25
29
 
26
30
 
27
31
  ###発生している問題・エラーメッセージ
@@ -268,10 +272,6 @@
268
272
 
269
273
  ```
270
274
 
271
- ###試したこと
272
-
273
- 課題に対してアプローチしたことを記載してください
274
-
275
275
 
276
276
 
277
277
  ###補足情報(言語/FW/ツール等のバージョンなど)

3

誤字

2016/04/16 12:36

投稿

mig2332
mig2332

スコア33

test CHANGED
@@ -1 +1 @@
1
- しょScaffoldに追加 resourcesで追加した際のエラー
1
+ Scaffoldに resourcesで追加した際のエラー
test CHANGED
File without changes

2

書式

2016/04/16 12:32

投稿

mig2332
mig2332

スコア33

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  resources :notes do
10
10
 
11
- get :rule
11
+ get 'rule'
12
12
 
13
13
  end
14
14
 
@@ -48,15 +48,189 @@
48
48
 
49
49
  ###該当のソースコードここに言語を入力
50
50
 
51
- routes.rb
51
+ notes_controller.rb
52
-
52
+
53
- ```
53
+ ```
54
+
54
-
55
+ class NotesController < ApplicationController
56
+
57
+
58
+
59
+
60
+
61
+ before_action :set_note, only: [:show, :edit, :update, :destroy, :rule]
62
+
63
+
64
+
55
- resources :notes do
65
+ # GET /notes
56
-
66
+
57
- get 'rule'
67
+ # GET /notes.json
68
+
58
-
69
+ def index
70
+
71
+ @notes = Note.all
72
+
59
- end
73
+ end
74
+
75
+
76
+
77
+ # GET /notes/1
78
+
79
+ # GET /notes/1.json
80
+
81
+ def show
82
+
83
+ end
84
+
85
+
86
+
87
+ # GET /notes/new
88
+
89
+ def new
90
+
91
+ @note = Note.new
92
+
93
+ end
94
+
95
+
96
+
97
+ # GET /notes/1/edit
98
+
99
+ def edit
100
+
101
+ end
102
+
103
+
104
+
105
+ def rule
106
+
107
+
108
+
109
+ end
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+ # POST /notes
118
+
119
+ # POST /notes.json
120
+
121
+ def create
122
+
123
+ @note = Note.new(note_params)
124
+
125
+
126
+
127
+ if params[:back]
128
+
129
+ render :new
130
+
131
+ elsif @note.save
132
+
133
+ redirect_to @note, notice:"作成完了"
134
+
135
+ else
136
+
137
+ render :new
138
+
139
+
140
+
141
+ end
142
+
143
+ end
144
+
145
+
146
+
147
+
148
+
149
+ # PATCH/PUT /notes/1
150
+
151
+ # PATCH/PUT /notes/1.json
152
+
153
+ def update
154
+
155
+ respond_to do |format|
156
+
157
+ if @note.update(note_params)
158
+
159
+ format.html { redirect_to @note, notice: 'アップロードが完了しました' }
160
+
161
+ format.json { render :show, status: :ok, location: @note }
162
+
163
+ else
164
+
165
+ format.html { render :edit }
166
+
167
+ format.json { render json: @note.errors, status: :unprocessable_entity }
168
+
169
+ end
170
+
171
+ end
172
+
173
+ end
174
+
175
+
176
+
177
+ # DELETE /notes/1
178
+
179
+ # DELETE /notes/1.json
180
+
181
+ def destroy
182
+
183
+ @note.destroy
184
+
185
+ respond_to do |format|
186
+
187
+ format.html { redirect_to notes_url, notice: '掲載が削除されました' }
188
+
189
+ format.json { head :no_content }
190
+
191
+ end
192
+
193
+ end
194
+
195
+
196
+
197
+ private
198
+
199
+ # Use callbacks to share common setup or constraints between actions.
200
+
201
+ def set_note
202
+
203
+ @note = Note.find(params[:id])
204
+
205
+ end
206
+
207
+
208
+
209
+ # Never trust parameters from the scary internet, only allow the white list through.
210
+
211
+ def note_params
212
+
213
+ params.require(:note).permit(:title, :content, :price, :image_1, :image_2, :image_3, :category, :rule)
214
+
215
+ end
216
+
217
+ end
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
60
234
 
61
235
 
62
236
 

1

初心者

2016/04/16 12:31

投稿

mig2332
mig2332

スコア33

test CHANGED
@@ -1 +1 @@
1
- Scaffoldに追加 resourcesで追加した際のエラー
1
+ しょScaffoldに追加 resourcesで追加した際のエラー
test CHANGED
File without changes