Last Updated: February 25, 2016
·
1.886K
· causztic

cocoon gem quirk

I was using simple forms, and renamed the form builder variable from f to s..well because I like the letter s more.

The form renders properly, until I wanted to add nested forms with cocoon.

I got the error of

undefined local variable or method `s' for #<#<Class:0x007fbc3bfa62f8>:0x007fbc3d8d28d0>

after following the demo on the github page. I read the documentation to read up on the parameters of

link_to_add_association

According to the page, the parameters are:

name: the text to show in the link

f: the form builder

association: the name of the association (plural) of which a new instance needs to be added (symbol or string).

html_options: extra html-options

When they mean f for form_builder, they really mean that the variable has to be the letter f. No kidding.

I grudgingly renamed my variable and the nested form worked.

3 Responses
Add your response

No kidding! Was fighting with this all day, futzing with render_options: { locals: .... }. Silly that I can't use whatever local variable I want, but thanks for the post!

over 1 year ago ·

ugh! wow, was messing with this for a few hours. thank you.
by the way, you made a little error here: 'until I wanted to added' => 'until I wanted to add'.

over 1 year ago ·

@lakesare thanks :)

over 1 year ago ·