Is is OK to use a non-primary key as the id in a rails resource?
Posted
by
nPn
on Programmers
See other posts from Programmers
or by nPn
Published on 2014-05-29T23:00:58Z
Indexed on
2014/05/30
3:50 UTC
Read the original article
Hit count: 164
I am getting ready to set up a resource for some new api calls to my rails application.
I am planning on calling the resource devices ie
resources :devices
This is going to represent a android mobile devices
I know this will get me routes such as
GET devices/:id
In most cases :id would be an integer representing the primary key, and in the controller we would use :id as such:
GET devices/1
@device = Device.find(params[:id])
In this case I would like to use :id as the google_cloud_messaging_reg_id
So I would like to have requests like this:
GET devices/some_long_gcm_id
and then in the controller , just us params[:id]
to look up the device by the gcm registration id. This seem more natural, since the device will know it's gcm id rather than it's rails integer id. Are there any reasons I should avoid doing this?
© Programmers or respective owner