teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

6

詳細

2020/03/14 09:23

投稿

anguraaaa
anguraaaa

スコア21

title CHANGED
File without changes
body CHANGED
@@ -1,9 +1,14 @@
1
1
  ### 前提・実現したいこと
2
2
  初めて質問させていただきます。
3
+
3
4
  railsでポイント管理サービスをつくっています。
4
5
  ポイント特典を作成する機能を実装中にエラーが発生しました。
5
- point_listの親要素であるcard_listのidをpoint_listへ渡せるようにしたいです。
6
6
 
7
+ 親要素(card_list)のindexページから子要素(point_list)のnewページに飛ばすpathでエラーが発生しています。
8
+ エラー文から親要素のidが取得できれば解決できると考えています。
9
+
10
+ なので、親要素(card_list)のidをpoint_listsコントローラーで子要素(point_list)へ渡せるようにしたいです。
11
+
7
12
  ### 発生している問題・エラーメッセージ
8
13
  point_listの親要素であるcard_listのidが空であると言われています。
9
14
 

5

index

2020/03/14 09:23

投稿

anguraaaa
anguraaaa

スコア21

title CHANGED
File without changes
body CHANGED
@@ -168,7 +168,7 @@
168
168
  ```
169
169
 
170
170
  ```
171
- views/card_lists/index.haml
171
+ views/card_lists/index.html.haml
172
172
 
173
173
  =render "layouts/header"
174
174
  .card_list-index-contents

4

index

2020/03/14 09:11

投稿

anguraaaa
anguraaaa

スコア21

title CHANGED
File without changes
body CHANGED
@@ -166,4 +166,38 @@
166
166
 
167
167
  end
168
168
  ```
169
+
170
+ ```
171
+ views/card_lists/index.haml
172
+
173
+ =render "layouts/header"
174
+ .card_list-index-contents
175
+ .index-contents
176
+ .index-contents__upper
177
+ .index-contents__upper__image
178
+ = image_tag @card_list.image, size: "166x150"
179
+ %h2.index-contents__upper__name
180
+ =@card_list.name
181
+ %ul.index-contents__upper__info
182
+ %li.index-contents__upper__address
183
+ ="住所: #{@card_list.address}"
184
+ %li.index-contents__upper__openig
185
+ ="営業時間: #{@card_list.opening_hours.strftime('%H:%M')} 〜 #{@card_list.closing_hours.strftime('%H:%M')}"
186
+ %li.index-contents__upper_tel
187
+ ="TEL: #{@card_list.phone_num}"
188
+ %li.index-contents__upper__url
189
+ ="URL:"
190
+ =auto_link(@card_list.url, html: { target: '_blank' })
191
+ .index-contents__upper__btn
192
+ =link_to "編集", "#", class: "index-contents__upper__btn__edit btn btn-warning"
193
+ =link_to "削除", "#", class: "index-contents__upper__btn__delete btn btn-danger"
194
+ .index-contents__middle
195
+ %h2.index-contents__middle__points
196
+ ポイント特典
197
+ =link_to "追加", "#", class: "index-contents__middle__points__add btn btn-success"
198
+ %h2.index-contents__middle__coupons
199
+ クーポン
200
+ =link_to "追加", "#", class: "index-contents__middle__coupons__add btn btn-success"
201
+ ```
202
+
169
203
  ここにより詳細な情報を記載してください。

3

routes

2020/03/14 09:11

投稿

anguraaaa
anguraaaa

スコア21

title CHANGED
File without changes
body CHANGED
@@ -134,6 +134,8 @@
134
134
  rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
135
135
  ```
136
136
  ```
137
+ routes.rb
138
+
137
139
  Rails.application.routes.draw do
138
140
  root "introduction#home"
139
141
 

2

ルーティング追加

2020/03/14 08:58

投稿

anguraaaa
anguraaaa

スコア21

title CHANGED
File without changes
body CHANGED
@@ -133,5 +133,35 @@
133
133
  update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
134
134
  rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
135
135
  ```
136
+ ```
137
+ Rails.application.routes.draw do
138
+ root "introduction#home"
136
139
 
140
+ # 消費者ユーザー
141
+ namespace :users, only: [:new, :create] do
142
+ get "/login", to: "sessions#new"
143
+ post "/login", to: "sessions#create"
144
+ delete "/logout", to: "sessions#destroy"
145
+ end
146
+
147
+ resources :users
148
+
149
+ # 管理者ユーザー
150
+ namespace :admins do
151
+ get "/login", to: "sessions#new"
152
+ post "/login", to: "sessions#create"
153
+ delete "/logout", to: "sessions#destroy"
154
+ end
155
+
156
+ resources :admins, only: [:new, :create] do
157
+ resources :card_lists, only: [:index, :new, :create] do
158
+ resources :point_lists, only: [:new, :create]
159
+ resources :coupon_lists, only: [:new, :create]
160
+ end
161
+ end
162
+
163
+ resources :admins
164
+
165
+ end
166
+ ```
137
167
  ここにより詳細な情報を記載してください。

1

エラーメッセージ表示

2020/03/14 08:57

投稿

anguraaaa
anguraaaa

スコア21

title CHANGED
File without changes
body CHANGED
@@ -6,11 +6,12 @@
6
6
 
7
7
  ### 発生している問題・エラーメッセージ
8
8
  point_listの親要素であるcard_listのidが空であると言われています。
9
- ```
9
+
10
10
  エラーメッセージ
11
11
  No route matches {:action=>"new", :admin_id=>#<CardList id: 2, admin_id: 2, name: "カレー", address: "大阪", opening_hours: "2000-01-01 11:30:00", closing_hours: "2000-01-01 23:00:00", phone_num: "0000000000", url: "https://www.ashoka-jp.com/", created_at: "2020-03-14 06:52:09", updated_at: "2020-03-14 06:52:09">, :controller=>"point_lists"}, missing required keys: [:card_list_id]
12
- ```
13
12
 
13
+
14
+
14
15
  ```
15
16
 
16
17
  ### 該当のソースコード