shallowを使ったroutingで、pathの設定がうまくいきません。
以下のように、shallowを使ったroutingで、accountsのshow.html.erbから、「item GET /items/:id(.:format) 」にアクセスしようとしてもできません。
(accountsはitemをhas_manyしている)
(エラー内容)
resources :accounts , shallow: true do resources :items, shallow: true do get :exhibit, on: :member end end 以下のpathが生成 #item GET /items/:id(.:format) #PATCH /items/:id(.:format) items#update # PUT /items/:id(.:format) items#update #DELETE /items/:id(.:format) items#destroy
accounts/show.html.erb
<% @account.items.each do |item| %> <p> <strong>商品名:</strong> <%= item.item_name %> <p> <strong>account_id:</strong> <%= item.account_id %> <p> <strong>id:</strong> <%= item.id %> <% if item.id != nil %> #ここでエラー発生 <p><%= link_to '商品詳細', item_path(item), account_id:item.account_id %></p> <% end %> </p> <% end %>
items_controller
def show @account = Account.find(params[:account_id]) @item = @account.items.find(params[:id]) end
エラー内容から察するに、link_toのitem_path(item)では、itemにひもづくidしか、paramsでおくれておらず、itemに紐付く、accoun_idが送信されていないのかと思い、「account_id:item.account_id」を付与しましたが、コンソールに出て来るパラメータを確認すると、送信できていませんでした。
解決出来る方が入れば教えてください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/22 14:29