Support for nested fields_for with alphanumeric keys #40

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

kibs commented Oct 4, 2012

Hi,

I was trying to get the nested_form gem working with strong_parameters. And I am having some trouble getting the two of them working nicely together.

Nested_form is using javascript for adding more or less nested fields for, when working with a model through a form. It is auto creating a unique index key for each set of fields, resulting in nested_attributes parameters with alphanumeric keys, instead of the normal integer based 0,1,2 etc.

I am not quite sure how to fix this, but i have added a failing test describing the problem. I could also try to change nested_form, but I think the solution would be more flexible if strong_parameters supported this.

One solution could be allowing the regexp, currently used for detecting integer based keys, to be changed in a configuration setting.

// Sune

Contributor
svoop commented Oct 4, 2012

I'm struggling with nested resources as well. However, your problem should IMHO be fixed on the nested_form gem. The prefix author_in keys such as author_1 inside the authors_attributes is redundant and inconsistent with out of the box nested forms. I'm not sure to what extend numeric keys may be a convention already, but it seems to make sense to stick to such a rule in order to keep other code working with the params hash (such as strong_parameters) as configuration free as possible.

kibs commented Oct 4, 2012

Thank you for your comments. I looked into the nested form gem, trying to understand why they prefix some with new_. It is to prevent clashes with the ids generated and existing ids in the db

ryanb/nested_form#21

@kibs kibs referenced this pull request in ryanb/nested_form Oct 4, 2012
Closed

Strong_parameters support #199

Contributor
svoop commented Oct 5, 2012

@kibs: Ah, good point, forgot about that.

kibs commented Oct 5, 2012

nested_form has removed the new prefix, the id is not taken from the key anyway. At least not anymore. I am closing this.

@kibs kibs closed this Oct 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment