質問編集履歴

2

画像の追加

2021/03/24 00:49

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -331,3 +331,9 @@
331
331
  end
332
332
 
333
333
  ```
334
+
335
+
336
+
337
+ ### 画像の追加
338
+
339
+ ![イメージ説明](f73d2e0077cf60c2dbbb425f0c786328.png)

1

追加修正の依頼

2021/03/24 00:49

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -184,36 +184,150 @@
184
184
 
185
185
  D, [2021-03-19T01:45:54.411340 #4] DEBUG -- : (11.6ms) BEGIN
186
186
 
187
- D, [2021-03-19T01:45:54.415574 #4] DEBUG -- : Category Create (3.1ms) INSERT INTO `categories` (`name`, `card_id`, `created_at`, `updated_at`) VALUES ('JavaScript', 3, '2021-03-19 01:45:54', '2021-03-19 01:45:54')
188
-
189
- D, [2021-03-19T01:45:54.433497 #4] DEBUG -- : (17.3ms) COMMIT
190
-
191
- D, [2021-03-19T01:45:54.443668 #4] DEBUG -- : (8.4ms) BEGIN
192
-
193
- D, [2021-03-19T01:45:54.446582 #4] DEBUG -- : Category Create (2.7ms) INSERT INTO `categories` (`name`, `card_id`, `created_at`, `updated_at`) VALUES ('Java', 4, '2021-03-19 01:45:54', '2021-03-19 01:45:54')
194
-
195
- D, [2021-03-19T01:45:54.462597 #4] DEBUG -- : (13.5ms) COMMIT
196
-
197
- D, [2021-03-19T01:45:54.477529 #4] DEBUG -- : (13.2ms) BEGIN
198
-
199
- D, [2021-03-19T01:45:54.480861 #4] DEBUG -- : Category Create (3.1ms) INSERT INTO `categories` (`name`, `card_id`, `created_at`, `updated_at`) VALUES ('PHP', 5, '2021-03-19 01:45:54', '2021-03-19 01:45:54')
200
-
201
- D, [2021-03-19T01:45:54.495516 #4] DEBUG -- : (14.0ms) COMMIT
202
-
203
- D, [2021-03-19T01:45:54.504649 #4] DEBUG -- : (7.2ms) BEGIN
204
-
205
- D, [2021-03-19T01:45:54.510290 #4] DEBUG -- : Category Create (5.4ms) INSERT INTO `categories` (`name`, `card_id`, `created_at`, `updated_at`) VALUES ('Python', 6, '2021-03-19 01:45:54', '2021-03-19 01:45:54')
206
-
207
- D, [2021-03-19T01:45:54.525963 #4] DEBUG -- : (15.1ms) COMMIT
208
-
209
- D, [2021-03-19T01:45:54.538182 #4] DEBUG -- : (9.0ms) BEGIN
210
-
211
- D, [2021-03-19T01:45:54.543277 #4] DEBUG -- : Category Create (4.8ms) INSERT INTO `categories` (`name`, `card_id`, `created_at`, `updated_at`) VALUES ('Ruby', 7, '2021-03-19 01:45:54', '2021-03-19 01:45:54')
212
-
213
- D, [2021-03-19T01:45:54.558613 #4] DEBUG -- : (14.7ms) COMMIT
187
+ D, [2021-03-19T01:45:54.415574 #4] DEBUG -- : Category Create (3.1ms) INSERT INTO `categories` (`name`, `card_id`, `created_at`, `updated_at`) VALUES ('JavaScript', 3,
188
+
189
+ 省略
214
190
 
215
191
  ```
216
192
 
217
193
 
218
194
 
219
195
  どなたかお助けしてくれると嬉しいです。宜しくお願い致します。
196
+
197
+
198
+
199
+ ### 追加
200
+
201
+ ルーティングになります
202
+
203
+ ```
204
+
205
+ Rails.application.routes.draw do
206
+
207
+ devise_for :users
208
+
209
+ root to: 'cards#index' #トップページへ遷移
210
+
211
+ resources :cards do#7つのアクションの省略
212
+
213
+ collection do
214
+
215
+ get 'search'
216
+
217
+ end
218
+
219
+ resources :categories, only: [:show]
220
+
221
+ end
222
+
223
+
224
+
225
+
226
+
227
+ end
228
+
229
+ ```
230
+
231
+
232
+
233
+ rails routesの結果になります
234
+
235
+ ```
236
+
237
+ Prefix Verb URI Pattern Controller#Action
238
+
239
+ new_user_session GET /users/sign_in(.:format) devise/sessions#new
240
+
241
+ user_session POST /users/sign_in(.:format) devise/sessions#create
242
+
243
+ destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
244
+
245
+ new_user_password GET /users/password/new(.:format) devise/passwords#new
246
+
247
+ edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
248
+
249
+ user_password PATCH /users/password(.:format) devise/passwords#update
250
+
251
+ PUT /users/password(.:format) devise/passwords#update
252
+
253
+ POST /users/password(.:format) devise/passwords#create
254
+
255
+ cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
256
+
257
+ new_user_registration GET /users/sign_up(.:format) devise/registrations#new
258
+
259
+ edit_user_registration GET /users/edit(.:format) devise/registrations#edit
260
+
261
+ user_registration PATCH /users(.:format) devise/registrations#update
262
+
263
+ PUT /users(.:format) devise/registrations#update
264
+
265
+ DELETE /users(.:format) devise/registrations#destroy
266
+
267
+ POST /users(.:format) devise/registrations#create
268
+
269
+ root GET / cards#index
270
+
271
+ search_cards GET /cards/search(.:format) cards#search
272
+
273
+ card_category GET /cards/:card_id/categories/:id(.:format) categories#show
274
+
275
+ cards GET /cards(.:format) cards#index
276
+
277
+ POST /cards(.:format) cards#create
278
+
279
+ new_card GET /cards/new(.:format) cards#new
280
+
281
+ edit_card GET /cards/:id/edit(.:format) cards#edit
282
+
283
+ card GET /cards/:id(.:format) cards#show
284
+
285
+ PATCH /cards/:id(.:format) cards#update
286
+
287
+ PUT /cards/:id(.:format) cards#update
288
+
289
+ DELETE /cards/:id(.:format) cards#destroy
290
+
291
+ ```
292
+
293
+
294
+
295
+ cardモデルになります
296
+
297
+ ```
298
+
299
+ class Card < ApplicationRecord
300
+
301
+ belongs_to :category, optional: true
302
+
303
+ def self.search(search) #self.クラスメソッド
304
+
305
+ if search != ""
306
+
307
+ Card.where('language LIKE(?) or title LIKE(?)', "%#{search}%","%#{search}%").order('id DESC') #言語、タイトルで検索することが可能
308
+
309
+ else
310
+
311
+ order('Id DESC')
312
+
313
+ end
314
+
315
+ end
316
+
317
+ end
318
+
319
+ ```
320
+
321
+
322
+
323
+ カテゴリーモデルになります
324
+
325
+ ```
326
+
327
+ class Category < ApplicationRecord
328
+
329
+ has_many :cards
330
+
331
+ end
332
+
333
+ ```