Ruby on rails 3.1 调用时路由错误";新";具有嵌套资源的方法
我有两个嵌套资源:Ruby on rails 3.1 调用时路由错误";新";具有嵌套资源的方法,ruby-on-rails-3.1,nested-resources,Ruby On Rails 3.1,Nested Resources,我有两个嵌套资源: class Customer < ActiveRecord::Base has_many :locations, :dependent => :destroy accepts_nested_attributes_for :locations end class Location < ActiveRecord::Base belongs_to :customer end 创建新位置的代码是 <%= link_to image_tag("a
class Customer < ActiveRecord::Base
has_many :locations, :dependent => :destroy
accepts_nested_attributes_for :locations
end
class Location < ActiveRecord::Base
belongs_to :customer
end
创建新位置的代码是
<%= link_to image_tag("add.png"), new_customer_location_path(@customer), :class => "button" %>
位置_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
我不理解这个错误,我有另外两个嵌套的资源可以正常工作,检查了所有的代码,看起来完全一样。。。
是否有可能“location”是一个保留字,或者有什么遗漏/错误?尝试在图像标签上加上一个右括号
<%= link_to image_tag("add.png"), new_customer_location_path(@customer), :class => "button" %>
“按钮”%>
好的,找到问题
内部应用程序/视图/位置/_form.html.erb
由app/views/locations/new.html.erb调用
存在与错误路径帮助器的链接:
<%= link_to "Cancel", customer_location_path(@customer,@location) %>
我把它改成了
<%= link_to "Cancel", customer_path(@customer) %>
现在一切正常了谢谢你的建议,但这只是写这篇文章时的一个打字错误;所有括号都可以。。。
<%= link_to "Cancel", customer_location_path(@customer,@location) %>
<%= link_to "Cancel", customer_path(@customer) %>