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!
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
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
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
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.
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.
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