0

I have routes in Rails application:

resources :products do
  get 'preview', to: 'products#preview', on: :member
    #member do
    #  get 'preview'
    #end
end

which defines route '/products/:id/preview'.

Products.id is bigint in a database.

When I open URL '/products/15/preview' it works fine. But when I open it with big id = 67500 which is bigger than max value for integer = 65535:

http://localhost:3000/products/67500/preview

it shows 404 error. Here id = 67500 which is bigger than Integer (65535) and the route doesn't work.

How to make Rails recognize id of BIGINT type ?

Max Ivak
  • 1,529
  • 17
  • 39

1 Answers1

1

Rajarshi Das is right - this is not a routes problem, but a database one.


DB

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.

To fix this, you need to change the id column to accommodate larger numbers:

$ 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
Community
  • 1
  • 1
Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • I already have column id of type bigint in the database. I restart server and now it works. Thanks! – Max Ivak Nov 05 '15 at 12:49