【问题标题】:Rails how to route when a resource_id intentionally does not exist?当故意不存在resource_id时Rails如何路由?
【发布时间】:2017-04-03 16:11:40
【问题描述】:

我目前正在设置一些内部页面,允许我的客户编辑他们的结算信息。但是,除了我的用户表中的stripe_customer_id 之外,所有信息都保存在 Stripe.com 上。

我设置了/billing 控制器、动作和路由。

现在我正在尝试导航到 /billing/card 页面,但我收到了这个 错误 missing required keys: [:billing_id]

显然我不打算有一个“billing_id”/计费表。

# routes      
resources :billing do
  get 'billing/customer_and_card', as: :card
end

我想到目前为止我只处理了存储在我的数据库中的对象/资源。路由时如何消除对resource_id 的需求?

【问题讨论】:

    标签: ruby-on-rails routing


    【解决方案1】:

    尽量不要将其设置为资源的一部分。

    类似这样的:

    get 'billing/card', to: 'billing#controller_action_here'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 2015-04-19
      • 2016-08-28
      相关资源
      最近更新 更多