下記のようにproductsを親、rewardsを子としネスト化しました。ネスト化した後、リンクタグにrewardscontroller#newに飛ぶパスを指定したのですが、なぜかproductscontroller#newが反応してしまいます。
routes
rb
1resources :products do 2 collection do 3 get'draft' 4 get'release' 5 end 6 resources :rewards 7 end
routing
rb
1new_product_reward GET /products/:product_id/rewards/new(.:format) rewards#new
link_to
rb
1<li class="nav-item active"> 2 <%= link_to 'お返し', new_product_reward_path, class:"nav-link" %> 3</li>
ターミナル
Started GET "/products/new" for ::1 at 2019-12-13 10:33:19 +0900 (0.1ms) SELECT sqlite_version(*) Processing by ProductsController#new as HTML User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 1], ["LIMIT", 1]] Rendering products/new.html.erb within layouts/application Rendered products/_form.html.erb (Duration: 18.4ms | Allocations: 2256) Rendered products/new.html.erb within layouts/application (Duration: 19.6ms | Allocations: 2601) [Webpacker] Everything's up-to-date. Nothing to do Completed 500 Internal Server Error in 59ms (ActiveRecord: 1.7ms | Allocations: 26042) ActionView::Template::Error (No route matches {:action=>"new", :controller=>"rewards"}, missing required keys: [:product_id]): 19: <ul class="navbar-nav mr-auto"> 20: 21: <li class="nav-item active"> 22: <%= link_to 'お返し', new_product_reward_path, class:"nav-link" %> 23: </li> 24: <li class="nav-item active"> 25: <%= link_to '下書きのみ', draft_products_path, class:"nav-link" %> app/views/layouts/application.html.erb:22
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/12/13 03:34
2019/12/13 03:44
2019/12/13 04:53
2019/12/13 04:55
2019/12/13 05:16
2019/12/16 00:43
2019/12/16 00:55 編集
2019/12/17 03:34