Skip to content
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

fields_for nested attributes #18

Open
fredwu opened this issue Aug 24, 2013 · 4 comments
Open

fields_for nested attributes #18

fredwu opened this issue Aug 24, 2013 · 4 comments
Assignees
Milestone

Comments

@fredwu
Copy link

fredwu commented Aug 24, 2013

Hi,

I noticed the following code snippet in lib/signed_form/form_builder:

def fields_for(record_name, record_object = nil, fields_options = {}, &block)
  hash  = {}
  array = []

  if nested_attributes_association?(record_name)
    hash["#{record_name}_attributes"] = fields_options[:signed_attributes_context] = array
  else
    hash[record_name] = fields_options[:signed_attributes_context] = array
  end

  add_signed_fields hash

  content = super
  array.uniq!
  content
end

It seems the hash["#{record_name}_attributes"] is simply an empty array. I assume this is intentional - but it also means that in our form (which by the way could be an issue in our form since we are not dealing with strictly ActiveRecord objects), blah_attributes will still get rejected because the array is empty.

In our form we have to manually call add_signed_fields with :blah_attributes => [:a, :b, :c] to get them accepted.

Is this by design? Any thoughts?

@fredwu
Copy link
Author

fredwu commented Aug 24, 2013

After further debugging, I nailed it down to being an issue caused by simple_fields_for. If I use fields_for, everything works, but using simple_fields_for doesn't. SignedForm::FormBuilder doesn't get initialised so the FIELDS_TO_SIGN loop never gets triggered for the nested fields.

I'll dig further.

@tubbo
Copy link
Contributor

tubbo commented Sep 11, 2013

This seems to be the same issue as #17. Does it only crop up when using SimpleForm?

@ready4god2513
Copy link

The issue on #17 that I am finding is that signed_form doesn't allow for the override of the scalar value. If you are using non AR values (hashes, arrays, etc) signed_form will mark the fields as strings, but arrays can get sent in (and rejected).

@Spaceghost Spaceghost self-assigned this Aug 6, 2014
@Spaceghost
Copy link
Collaborator

I might need some help looking into this. @tubbo, do you have any context on this?

@Spaceghost Spaceghost removed their assignment Feb 27, 2018
@Spaceghost Spaceghost added this to the 1.0 milestone Feb 27, 2018
@Spaceghost Spaceghost self-assigned this Feb 27, 2018
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

4 participants