[英]Rails doesn't see Bigint id in routes
I have routes in Rails application: 我在Rails应用程序中有路线:
resources :products do
get 'preview', to: 'products#preview', on: :member
#member do
# get 'preview'
#end
end
which defines route '/products/:id/preview'. 定义路由“ / products /:id / preview”。
Products.id is bigint in a database. Products.id在数据库中为bigint。
When I open URL '/products/15/preview' it works fine. 当我打开URL'/ products / 15 / preview'时,它工作正常。 But when I open it with big id = 67500 which is bigger than max value for integer = 65535:
但是,当我用大id = 67500打开它时,它大于整数= 65535的最大值:
http://localhost:3000/products/67500/preview
it shows 404 error. 它显示404错误。 Here id = 67500 which is bigger than Integer (65535) and the route doesn't work.
这里的id = 67500,比Integer(65535)大,并且路由无效。
How to make Rails recognize id of BIGINT type ? 如何使Rails识别BIGINT类型的ID?
Rajarshi Das
is right - this is not a routes problem, but a database one. Rajarshi Das
是对的-这不是路由问题,而是数据库问题。
DB D B
The routes part of your system will just be sending the required params to your controller. 系统的路由部分将只是将所需的参数发送到控制器。 It has no bearing on the size of the number you're sending - it's "dumb".
它与您要发送的号码大小无关-它是“哑巴”。
The problem appears to be with your database - unable to look up the id
you've requested. 问题似乎出在您的数据库上-无法查找您所请求的
id
。
To fix this, you need to change the id
column to accommodate larger numbers : 要解决此问题,您需要更改
id
列以容纳更大的数字 :
$ rails g migration ChangeIDProducts
#db/migrate/change_id_products______.rb
class ChangeIdProducts < ActiveRecord::Migration
def change
change_column :products, :id, limit: 20
end
end
$ rake db:migrate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.