我试图修改我的脚本,我正在从rails 2.3迁移到rails 3.1,但我面临着一个奇怪的问题。我看到当我使用像这样的路径助手时
在rails 3.1中,我得到了一个异常,但rails 2.3曾经工作过,我的意思是,当我传递值给路径助手( order.customer_id为0)时,它会生成一个创建新客户的路径,但是在rails 3.1中,它会生成一个异常,下面是我在rails 3.1中看到的错误描述。
helper.link_to customer_email, app.store_customer_path(store,order.customer_id),当order.customer_id为空时,我在控制台上得到一个异常,如下所示
下面是我在rails 2.3中观察到的错误
ActionController::RoutingError:{:controller=>"customers", :action=>"show", :store_id=#<object>}生成store_customer_url失败
。但是,当我加载一个网页时,我会看到我得到了一条创建新客户的路径。
这是我的相关routes.rb代码
resources :stores do
resources :customers do
collection do
get :get_customers, :download, :csv_template
end
match :upload, :import, :map, :on => :collection
member do
get :more
end
resources :dropship_profiles
resources :address
end
end但在rails 3.1中
在控制台上,我看到异常,当从浏览器加载时,我也看到异常
我无法理解这一点,它使我困惑,谁能帮忙,谢谢。
发布于 2015-07-13 11:19:20
在浏览完您的routes.rb之后,我没有看到任何相关的路径,这些路径可以路由到store_customer_path...kindly,使用当前的路径或者通过运行rake routes > path.txt创建新的one...verify,然后在path.txt中轻松地检查您的路由
=============UPDATED ANSWER==============
在这里,您传递两个值,只需传递一个
代替helper.link_to customer_email, app.store_customer_path(store,order.customer_id) 尝试
helper.link_to customer_email, app.store_customer_path(order.customer_id)或
helper.link_to customer_email, app.store_customer_path(store.id)正如您的path所说的/stores/:store_id/customers/new(.:format),您只需要通过store_id才能使其工作。
要了解从Rails 2到Rails 3路由的主要更改,...you必须查看这个页面
https://stackoverflow.com/questions/31379549
复制相似问题