So if I do this:

class Errors < ActiveRecord::Base
    def crtd_x
      crtd.strftime("%Y-%m-%d")
    end
    ...
end

errs = Errors.find(:all, :conditions => ...)

errs.to_xml(:methods => [:crtd_x, ...])

It fails with a NoMethodError: You have a nil object when you didn't
expect it!
The error occurred while evaluating nil.strftime

If I understand correctly, Errors (a subclass of ActiveRecord::Base)
contains a list of rows, each of which would have a field called
"crtd".  But at the level I'm calling to_xml, there is no field
"crtd".  What I need for my custom function is something like this
(pseudocode):

def crtd_x
  current_error.crtd.strftime("%Y-%m-%d")
end

I think I'm close.  Please advise how I can make crtd_x() operate on
the current item in the collection rather than on the whole
collection.

Thanks much,
Michael



On Jan 9, 4:34 am, MaD <[email protected]> wrote:
> i honestly don't know. but still i'm eager to learn. here is something
> i found on google:
>
> [quote]
>  If I were facing this dilemma, I would add a method on the
> model that returns the date in the format that you need it:
>
> def updated_at_js
>     updated_at.strftime(<some format>)
> end
>
> Then call to_xml like this:
>
> p = Person.find_by_id(params[:id])
> p.to_xml :methods => :updated_at_js
>
> so the properly formatted date is included in the xml packet. Then
> just
> use that one in your JS.
> [/quote]
>
> let me know when you've found a solution to that problem.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to