Simple_form: Cannot access object from form builder

Created on 7 Mar 2013  Â·  1Comment  Â·  Source: heartcombo/simple_form

Hi!

I cannot access the object from form builder when using simple_fields_for. In standard form_form @resource do |builder| i could access the object just using: builder.object.

Is there a way to access the object from the simple form builder?

= simple_form_for @request do |f|
  %table.table
    = f.simple_fields_for(:orders) do |of|
      %tr
        %td{ style: 'padding: 4px;' }= of.object.product.name_with_identifier
        %td{ style: 'padding: 4px;' }= "-"
        %td{ style: 'padding: 4px;' }= of.input :quantity, label: false, wrapper_html: { style: 'margin: 0px; padding: 0px;' }, input_html: { style: 'margin: 0px: padding: 0px; line-height: 1em; width: 30px;' }

the error is undefined method `product' for nil:NilClass

Just in case i'm adding some versions info:

➜  lab git:(dev) ✗ bundle show simple_form
/Users/mark/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/simple_form-2.0.4

Thanks in advance!

Most helpful comment

It's supposedly the same way, the object should be available for you. The point is that you're trying to access an object from the of builder, which has apparently no object (since it's tied to the symbol :orders). If you access f.object, you'll see that it's there.

Perhaps you're trying to create a nested form and forgot to add accepts_nested_attributes_for in the model?

>All comments

It's supposedly the same way, the object should be available for you. The point is that you're trying to access an object from the of builder, which has apparently no object (since it's tied to the symbol :orders). If you access f.object, you'll see that it's there.

Perhaps you're trying to create a nested form and forgot to add accepts_nested_attributes_for in the model?

Was this page helpful?
0 / 5 - 0 ratings