Ruby on Rails Thursday, July 29, 2010

Hello,

I know this issues is a couple of weeks old, but was still one of the
more recent hits I found when looking for discussions of apn_on_rails.

On Jul 12, 10:47 am, Greg Ma <li...@ruby-forum.com> wrote:
> Amit Kumar wrote:
> > I mean device.id represents your token from apn_devices table.

This is really an ActiveRecord issue ... device.id is the database
identifier of the record, not the APN token (which is "token").

In the code above, instead of assigning the to token to "device.id",
assign it to "device.token". Then save the record: "device.save", and
if you get back 'true', you can procede with the rest of your code.
As id is an int, you couldn't put a string in there, which is what the
token is. You'd get an error when trying to save, and the token field
wouldn't be populated.

Just remember, unless you're stepping off the 'golden path' (and only
do so when you need to and know what you're doing), with ActiveRecord,
the 'id' field does not have any business data in it, it is just there
to identify the record itself, in most cases, automatically assigned
(possibly not with Oracle, but that's another story). It can be
useful to assign without having to actually retrieve a record, e.g.,

class User < ActiveRecord::Base
belongs_to :office
end

Then, if you know the LA office is #3 e.g., you can do

someuser.office_id = 3
someuser.save

instead of

someuser.office = Office.find_by_name("LA")
someuser.save

which will have to fetch another record, if Rails hasn't cached it
already. It is frequent in controllers you'll have a record number
rather than a record, coming back in the params from a form.

But in many cases, you can pretty much ignore the ID field.

Good luck,
Craig

>
> I don't understand... I would it look like in production???
>
> Greg
>
> --
> Posted viahttp://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment