ルーティングはネストさせてあり、以下のようになっています。
routes.rb Rails.application.routes.draw do root 'products#index' resources :products do resources :characteristics, only: [:new] end end
そして、productsコントローラーのshowメソッドからcharacteristicsコントローラーのnewメソッドの画面へと遷移させ、データを入力していきたいのですが、パスが通りません。
/products/views/show.html.erb <h1>詳細ページ</h1> <div class="profile_list"> <table> <theader> <tr> <th>メーカー</th> <th>モデル</th><th>価格</th><th>詳細</th><th>編集</th><th>削除</th> </tr> </theader> <tbody> <tr> <td> <%= @product.maker %> </td> <td> <%= @product.model %> </td> <td> <%= @product.price %> </td> <td> <%= link_to "特性を追加", "/products/#{@product.id}/characteristics/new", method: :get %> </td> <td> <%= link_to "編集", edit_product_path(@product.id), method: :get %> </td> <td> <%= link_to "削除", product_path(@product.id), :method => :delete %> </td> </tr> </tbody> </table> </div>
/characteristics/views/new.html.erb <%= form_for @characteristic do |f| %> <div> <%= f.label :characteristic %> <%= f.text_field :characteristic, :class => "form-control" %> </div> <% end %>
こちらがエラー内容です。
NoMethodError in Characteristics#new undefined method `characteristics_path' for #<#<Class:0x007fbea1b8a800>:0x007fbea8173950> <%= form_for @characteristic do |f| %> <div> <%= f.label :characteristic %> <%= f.text_field :characteristic, :class => "form-control" %> </div>
ネストさせていなければ、パスは通るっぽいのですが、ネストさせてからだと記述を加える必要があるのでしょうか?
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/17 01:01