2 つのネストされたリソースがあります。
class Customer < ActiveRecord::Base
has_many :locations, :dependent => :destroy
accepts_nested_attributes_for :locations
end
class Location < ActiveRecord::Base
belongs_to :customer
end
routes.rb には
resources :customers do
resources :locations
end
新しい場所を作成するためのコードは次のとおりです。
<%= link_to image_tag("add.png"), new_customer_location_path(@customer), :class => "button" %>
新しい場所を作成しようとすると、次のエラーが表示されます
ルーティング エラー
{:action=>"show", :controller=>"locations", :customer_id=>#, :id=>#} に一致するルートはありません
「new」の代わりに :action=>「show」が呼び出されるのはなぜですか?
rake routes 出力は
customer_locations GET /customers/:customer_id/locations(.:format) {:action=>"index", :controller=>"locations"}
POST /customers/:customer_id/locations(.:format) {:action=>"create", :controller=>"locations"}
new_customer_location GET /customers/:customer_id/locations/new(.:format) {:action=>"new", :controller=>"locations"}
edit_customer_location GET /customers/:customer_id/locations/:id/edit(.:format) {:action=>"edit", :controller=>"locations"}
customer_location GET /customers/:customer_id/locations/:id(.:format) {:action=>"show", :controller=>"locations"}
PUT /customers/:customer_id/locations/:id(.:format) {:action=>"update", :controller=>"locations"}
DELETE /customers/:customer_id/locations/:id(.:format) {:action=>"destroy", :controller=>"locations"}
location_controller.rb の新しいアクションのコントローラー コードは次のとおりです。
before_filter :find_customer
def new
@location = @customer.locations.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @location }
end
end
エラーがわかりません。正しく動作する別の 2 つのネストされたリソースがあり、すべてのコードをチェックしましたが、まったく同じように見えます... ?