8000 erector support for fields_for_with_nested_attributes · Issue #10 · erector/erector · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

erector support for fields_for_with_nested_attributes #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
learnist opened this issue Aug 31, 2010 · 1 comment
Open

erector support for fields_for_with_nested_attributes #10

learnist opened this issue Aug 31, 2010 · 1 comment

Comments

@learnist
Copy link

We have a model which declares accepts_nested_attributes_for on one of its has_many associations. When we try to call fields_for for that association, we get a TypeError: "can't convert nil into String". This is coming from ActionView's FormHelper class:

actionpack-2.3.2/lib/action_view/helpers/form_helper.rb:1023:in 'fields_for'
actionpack-2.3.2/lib/action_view/helpers/form_helper.rb:1021:in 'fields_for_nested_model'
actionpack-2.3.2/lib/action_view/helpers/form_helper.rb:1010:in 'fields_for_with_nested_attributes'
actionpack-2.3.2/lib/action_view/helpers/form_helper.rb:1009:in 'map'
actionpack-2.3.2/lib/action_view/helpers/form_helper.rb:1009:in 'fields_for_with_nested_attributes'
actionpack-2.3.2/lib/action_view/helpers/form_helper.rb:950:in 'fields_for'
erector-0.8.1/lib/erector/rails/rails_form_builder.rb:12:in 'send'
erector-0.8.1/lib/erector/rails/rails_form_builder.rb:12:in 'method_missing'

Have you seen this problem before? We're considering extending Erector::RailsFormBuilder to implement fields_for_with_nested_attributes in a manner similar to the way you've done form_for and fields_for. Would you recommend this approach, or something else?

Thanks from the Grockit team.

@learnist
Copy link
Author
learnist commented Sep 1, 2010

You can disregard this, it turns out; we think this may just be an idiosyncrasy of combining Erector 0.8.1 with Rails 2.3.2. The problem was this line from ActionView::Helpers::FormBuilder#fields_for_nested_model:

@template.concat builder.hidden_field(:id)

FormBuilder expects hidden_field to return a string, but Erector::RailsFormBuilder does the concatenation itself and returns nil. We came up with the following workaround:

module Erector
  class RailsFormBuilder
    def hidden_field(*args, &block)
      template.concat(parent.hidden_field(*args, &block))
      return ""
    end
  end
end

Any thoughts on this approach?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants
0