Railsアプリで既存の足場モデルの新しいビューを手動で作成しました。これがポイントだと思ったので、同じモデルに対して複数のビューを作成できるからです。ビュー内の項目に link_to しようとすると、Rails から間違った URL が返されることを除いて、すべて正常に機能しているようです。
- routes.rb には適切な「resources :controller」があります
- controller_controller.rb が存在し、正常に動作します
- views/controller/show.html.erb が存在し、正常に動作します
- link_to "controller", controller_path #正常に動作します
link_to "controller", controller_path(object) # コントローラーにリンクしますが、ID を "/id" ではなく ".id" として追加します
理由はありますか?
rake ルート出力
pups GET /pups(.:format) {:action=>"index", :controller=>"pups"}
POST /pups(.:format) {:action=>"create", :controller=>"pups"}
new_pup GET /pups/new(.:format) {:action=>"new", :controller=>"pups"}
edit_pup GET /pups/:id/edit(.:format) {:action=>"edit", :controller=>"pups"}
pup GET /pups/:id(.:format) {:action=>"show", :controller=>"pups"}
PUT /pups/:id(.:format) {:action=>"update", :controller=>"pups"}
DELETE /pups/:id(.:format) {:action=>"destroy", :controller=>"pups"}