using fields_for in a partial

56 views
Skip to first unread message

bertly_the_coder

unread,
May 7, 2014, 6:26:55 AM5/7/14
to rubyonra...@googlegroups.com
Hi guys,

I've been coding in rails for a while now but I've never been able to render fields_for as a partial. I don't know if this is possible, as it should be dead simple. Normally when I run across this problem, I just find another way to do it.....but sadly, it's time to pay the piper....any help would be greatly appreciated.
My code looks like so:

#form.html.haml
=render partial: "html_panel_fields", locals:{f: f}
 
and my partial looks like this 
 
#_ html_panel_fields.html.haml
= f.simple_fields_for :html_panels do |o|

my error is as follows:
undefined local variable or method `f' for #<#<Class:0x007fdf7077c8e0>:0x007fdf72175738>

It looks like I have two classes embedded here......what gives?

Thanks! 
 

Colin Law

unread,
May 7, 2014, 7:01:07 AM5/7/14
to rubyonra...@googlegroups.com
On 7 May 2014 11:26, bertly_the_coder <muc...@gmail.com> wrote:
> Hi guys,
>
> I've been coding in rails for a while now but I've never been able to render
> fields_for as a partial. I don't know if this is possible, as it should be
> dead simple. Normally when I run across this problem, I just find another
> way to do it.....but sadly, it's time to pay the piper....any help would be
> greatly appreciated.
> My code looks like so:
>
> #form.html.haml
>
> =render partial: "html_panel_fields", locals:{f: f}
>
>
> and my partial looks like this
>
> #_ html_panel_fields.html.haml
>
> = f.simple_fields_for :html_panels do |o|
>
>
> my error is as follows:
>
> undefined local variable or method `f' for
> #<#<Class:0x007fdf7077c8e0>:0x007fdf72175738>

In the text you said you could not use fields for, but in the example
you are using simple_fields_for. Please clarify.

Is it only if you use f in another way in the partial is it ok? In
other words is it anything to do with fields for at all?

Can you confirm that the it is the line in the partial that is
failing, not the render line?

Colin
Message has been deleted

Colin Law

unread,
May 7, 2014, 7:09:51 AM5/7/14
to rubyonra...@googlegroups.com
On 7 May 2014 12:06, bertly_the_coder <muc...@gmail.com> wrote:
> I'm using simple_fields_for but have had the same error with fields_for, my
> bad. simple_fields_for is from the simple form gem

Is that in reply to my questions? If so then please quote the
previous message and insert replies inline so that it is easier to
follow the thread. That would also help to ensure you remember to
fully answer all the questions, which you have not.

Colin
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/fb3b602b-1acb-4714-ab20-9949a4809981%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

bertly_the_coder

unread,
May 7, 2014, 7:28:08 AM5/7/14
to rubyonra...@googlegroups.com
Does anyone else, except Colin, know why one can place the fields of for simple_fields_for/fields_for in a partial and that works correctly but when one places the actual simple_fields_for/fields_for declaration in the partial it breaks?


On Wednesday, May 7, 2014 1:26:55 PM UTC+3, bertly_the_coder wrote:

Colin Law

unread,
May 9, 2014, 4:04:20 AM5/9/14
to rubyonra...@googlegroups.com
On 7 May 2014 12:28, bertly_the_coder <muc...@gmail.com> wrote:
> Does anyone else, except Colin, know why one can place the fields of for
> simple_fields_for/fields_for in a partial and that works correctly but when
> one places the actual simple_fields_for/fields_for declaration in the
> partial it breaks?

Apparently not, though it would be more likely if you fully answered
the questions I originally asked.

Colin

and...@benjamin.dk

unread,
May 9, 2014, 5:12:23 AM5/9/14
to rubyonra...@googlegroups.com
answering questions aside, 

you can see your problem is that f is not recognized on your partial. Have you tried raising it? probably it's nil, then you are not passing the variable correctly!

can we see your whole form view?(probably use a gist), also which version of rails and ruby you are using?

About what Collin is asking you, is that you have to have to follow some rules, a sort of protocol to ask questions here, for us to be able to help you. it will make yours and ours life easier. 

Colin Law

unread,
May 9, 2014, 5:34:13 AM5/9/14
to rubyonra...@googlegroups.com
Just to clarify, the questions that have not been answered are whether
the problem occurs on the line calling the partial or inside the
partial, and if f is used for something other than fields_for whether
the problem still occurs.

Colin

>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/c659a8dc-2326-4e2f-ac18-1d45d3137c86%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages