首页 文章

路径助手在从Rails-2迁移到Rails-3时在控制台上生成异常

提问于
浏览
0

我正在尝试修改我的脚本,我正在从rails 2.3迁移到rails 3.1但我面临一个奇怪的问题 . 我看到当我使用这样的路径助手时

在rails 3.1我得到一个例外,但它曾经工作的轨道2.3,通过工作我的意思是什么时候路径助手我传递值和order.customer_id是零,它生成一个创建新客户的路径,但在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:store_customer_url无法从 {:controller=>"customers", :action=>"show", :store_id=#<object>} 生成

. 但是当我加载一个网页时,我看到我得到了一条路径来创建一个新客户 .

这是我的相关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中

在控制台上,我看到异常,当从浏览器加载时,我也看到异常

我无法理解这一点,让我感到困惑,任何人都可以帮忙,谢谢 .

1 回答

  • 0

    经过你的 routes.rb 之后,i dont see 路由到 store_customer_path 的任何相关路径......请使用现有的路径或创建新路径...通过运行 rake routes > path.txt 验证然后在 path.txt 中轻松检查路线

    =============UPDATED ANSWER==============

    这里你传递两个值,你只需传递一个

    而不是 helper.link_to customer_email, app.store_customer_path(store,order.customer_id) try

    helper.link_to customer_email, app.store_customer_path(order.customer_id)
    

    or

    helper.link_to customer_email, app.store_customer_path(store.id)
    

    正如你的路径所说 /stores/:store_id/customers/new(.:format) ,你只需要传递store_id就可以了 .

    了解 major changes in Routes from Rails 2 to Rails 3 ...你必须看一下page

相关问题