我有兩個嵌套的資源:路由錯誤呼喚「新」的方法與嵌套資源
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" %>
當我嘗試創建新位置時,出現以下錯誤
路由錯誤
沒有路由匹配{:動作=> 「秀」,:控制器=> 「位置」,:CUSTOMER_ID =>#:ID =>#}
爲什麼:動作=>」顯示「被調用而不是」新「?
耙路輸出
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"}
在locations_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
我不明白的錯誤,我有正常工作,另外兩個嵌套資源,檢查了所有的代碼,看起來完全一樣... 「位置」是保留字還是有缺失/錯誤?
感謝這個建議,但這只是一個錯字,寫這篇文章;所有的括號都可以... – kranz 2011-12-21 17:37:12