Christophe,

I mistyped my JSON:

var group_with_admin = {"attributes" : {"name" : "Group 1"}, "users" :
[{"attributes" : { "first" : "John"}}]};

users is an array. So I tried this:

var groupTemplate = new Template('#{attributes.name} is administered
by #{users[0].attributes.first}');

Thanks to your fix, #{attributes.name} renders "Group 1", but I can't
get to "John". My active record object is the result of this finder:

Group.find(:first, :include => :users)

where groups have many users.

I presume this isn't such a straight-forward fix. Any pointers? This
is the first time I've actually looked at the source code for
prototype - shame on me!

Regards

Adam



On Apr 20, 11:12 am, addywaddy <[EMAIL PROTECTED]> wrote:
> A reply from the mighty Christophe!
>
> Thanks for this mate. That'll make it child's play for updating the
> page with an array of active record objects.
>
> All the best
>
> Adam
>
> On Apr 20, 11:04 am, Christophe Porteneuve <[EMAIL PROTECTED]> wrote:
>
> > Hi Adam,
>
> > addywaddy a écrit :
>
> > > var groupTemplate = new Template('#{attributes.name} is administered
> > > by #{users.attributes.first}');
>
> > Currently Template only uses direct properties of the evaluated object:
> > it doesn't go down.  That's rather simple to fix, though.  I'll consider
> > a patch soon about this, in the meantime here's a working fix:
>
> >    evaluate: function(object) {
> >      return this.template.gsub(this.pattern, function(match) {
> >        var before = match[1];
> >        if (before == '\\') return match[2];
> > // START OF FIX
> >        var obj = object;
> >        match[3].split('.').each(function(comp) {
> >          if (obj)
> >            obj = obj[comp];
> >        });
> >        return before + String.interpret(obj);
> > // END OF FIX
> >      });
> >    }
>
> > --
> > Christophe Porteneuve aka TDD
> > [EMAIL PROTECTED]


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" 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-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to