生产中的Rails路由正在寻找param:id。如何告诉它使用:order_id?

时间:2014-05-08 15:44:59

标签: ruby-on-rails heroku path routes

我最近将远程数据库连接到我网站的生产版本。但是,现在我的路线不起作用了。

在我的Heroku日志中,我的应用正在寻找Parameters: {"id"=>"edit"}.

但我的数据库中没有:id参数。指定的唯一索引是 order_id

如何编辑 routes.db ,以便在我的路径中使用 order_id ?这是甚至是必要的还是还有其他我应该看的东西?

本地数据库中的列列表:

1.9.3-p392 :001 > Order.column_names
 => ["order_id", "product_status", "img_reference", "img_source", "user_email", "user_name", "user_address", "user_city", "user_zipcode", "user_state", "product_size", "product_type", "payment_id", "image_file_name", "image_content_type", "image_file_size", "image_updated_at"] 

远程数据库中的列列表:

irb(main):001:0> Order.column_names
=> ["order_id", "order_date", "product_status", "img_reference", "img_source", "user_email", "user_name", "user_address", "user_city", "user_zipcode", "user_state", "product_size", "product_type", "uservendor_id", "paypal_confirmation"]

同样,我的路线似乎在我的开发版本中运行良好。

我能想到的唯一区别是我的远程数据库中有一些额外的列,我认为这些列不会影响路径。

这是我在Heroku日志中遇到的错误:

2014-05-08T15:28:55.461192+00:00 app[web.1]: Started GET "/orders//edit" for 76.102.227.168 at 2014-05-08 15:28:55 +0000
2014-05-08T15:28:55.465958+00:00 app[web.1]: Processing by OrdersController#show as HTML
2014-05-08T15:28:55.461180+00:00 app[web.1]: Started GET "/orders//edit" for 76.102.227.168 at 2014-05-08 15:28:55 +0000
2014-05-08T15:28:55.465965+00:00 app[web.1]: Processing by OrdersController#show as HTML
2014-05-08T15:28:55.465988+00:00 app[web.1]:   Parameters: {"id"=>"edit"}
2014-05-08T15:28:55.466009+00:00 app[web.1]:   Parameters: {"id"=>"edit"}
2014-05-08T15:28:55.469914+00:00 app[web.1]: Completed 404 Not Found in 4ms
2014-05-08T15:28:55.469922+00:00 app[web.1]: Completed 404 Not Found in 4ms
2014-05-08T15:28:55.470930+00:00 app[web.1]: 
2014-05-08T15:28:55.470933+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find Order without an ID):
2014-05-08T15:28:55.470935+00:00 app[web.1]:   app/controllers/orders_controller.rb:69:in `set_order'
2014-05-08T15:28:55.470938+00:00 app[web.1]: 
2014-05-08T15:28:55.470937+00:00 app[web.1]: 
2014-05-08T15:28:55.470943+00:00 app[web.1]: 
2014-05-08T15:28:55.470945+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find Order without an ID):
2014-05-08T15:28:55.470946+00:00 app[web.1]:   app/controllers/orders_controller.rb:69:in `set_order'
2014-05-08T15:28:55.470948+00:00 app[web.1]: 
2014-05-08T15:28:55.470949+00:00 app[web.1]: 

1 个答案:

答案 0 :(得分:0)

因此,在ActiveRecord中,如果您有自定义主键,则需要在模型中指定它

class Order
  self.primary_key = :order_id

文档:http://guides.rubyonrails.org/active_record_basics.html#overriding-the-naming-conventions