Re: Parents, Children & Grandchildren in one form

1 view
Skip to first unread message

MaoTseTung

unread,
Sep 23, 2008, 7:04:45 PM9/23/08
to attribute_fu
I'm trying to create a form with one parent and multiple children,
each with multiple grandchildren based on the pastie that pimpmaster
posted (http://pastie.textmate.org/163163) and I'm having a couple of
issues. Hoping someone can shed some light on this.

One problem is getting the grandchildren to add to the appropriate
child DIV tag since the names are all the same. For example, within
the parent form I have:

id=children
class=child
id=grand_children
class=grand_child
class=grand_child
< %= f.add_associated_link('Add Grandchild',
child.grand_children.build) % >
class=child
id=grand_children
class=grand_child
class=grand_child
< %= f.add_associated_link('Add Grandchild',
child.grand_children.build) % >

There are two sets of grandchildren, one for each child. However the
add_associated_link for both sets just adds to the first
"grand_children" DIV. The only way I could think of to get around
this was to add an associated child.id to the grand_children class
name. So it becomes something like:

< %= f.add_associated_link('Add Grandchild',
child.grand_children.build, {:container => "grand_children" +
child.id.to_s}) % >

This works fine so for for adding grandchildren to the appropriate DIV
but I'm not sure if this is the best way to do this and if it'll even
work once I start dynamically adding more children using the
add_associated_link. I haven't been able to test that yet...which
brings me to the second issue.

Once I added grandchildren into the mix, I get a "missing ] after
element list" javascript error when trying to add a child. This only
occurs when the child partial contains the add_associated_link for
adding grandchildren.

From what I can tell I'm using version 0.2.1.

Can someone who's gotten this working help?

MaoTseTung

unread,
Sep 25, 2008, 10:15:58 PM9/25/08
to attribute_fu
Ok nevermind the first problem. Figured out how :expression works and
realized I could use it to add the items to the appropriate DOM
element even if there were duplicate id names.

However I'm still getting a "missing ] after element list" javascript
error when I try to add a child. The error only occurs when I include
an add_associated_link on the grandchild partial. Not sure if certain
characters aren't getting escaped properly with the nested grandchild
add_associated_link's javascript.

Am I the only getting this error? Anyone who's gotten this to work
care to share?

Thanks.

James Golick

unread,
Oct 5, 2008, 7:07:03 PM10/5/08
to attrib...@googlegroups.com
Try the latest version from github: http://github.com/giraffesoft/attribute_fu

Jason

unread,
Oct 8, 2008, 7:06:59 PM10/8/08
to attribute_fu
I am still getting " missing ) after argument list " when using
grandchildren on the latest from the jquery branch.

MaoTseTung

unread,
Oct 10, 2008, 6:43:42 PM10/10/08
to attribute_fu
I already have the latest version. I downloaded again just to make
sure and it didn't solve the problem.

I believe this may be the issue:
http://dev.rubyonrails.org/ticket/7381

Sounds like the exact problem I'm having with the double escaped
javascript.
'The problem appears to be that when javascript is double-escaped
"&quot;" does not get escaped to "&amp;quot". '

I'm not sure if modifying the add_associated_link method to not use
Prototype will fix this...seems like the bug is in the Rails code.


On Oct 5, 4:07 pm, "James Golick" <jamesgol...@gmail.com> wrote:
> Try the latest version from github:http://github.com/giraffesoft/attribute_fu
>

Jason

unread,
Oct 12, 2008, 12:39:46 AM10/12/08
to attribute_fu
Now that we know what it might be is there anyway to fix or patch this?

SirSparrowHawk

unread,
Nov 21, 2008, 11:29:56 PM11/21/08
to attribute_fu
I too am having the "missing ] after element list" problem, with rails
2.1.1 or 2.2.2 and attribute_fu 0.2.1 or master git.

As OP states, the problem appears to occur only when a child contains
an add_associated_link for grandchildren, and appears to be a quoting
problem with the grandchild add_associated_link, however, I can't
think of a 'right' way to address the problem.

Some suggestions from someone who's actually gotten this to work would
be greatly appreciated.
Reply all
Reply to author
Forward
0 new messages