Proposed functionality in strong parameters to transform an attribute into nested_attributes format

Recently i’ve been working on a javascript frontend/ rails backend project.

In one view their are several models that are posting to a users controller. The user is accepting nested attributes for these 3 other models.

When the params get there, they arrive as things like educations, trainings, courses. In order to get them to be accepted we put them through a transform that took each one and appended _attributes to the key. So educations => educations_attributes.

It would be nice if strong parameters had a method. Something like permit_nested that would do this translation if it didn’t exist.

I am happy to do the work and pr but wanted to get feed back first.

This is a user error, the f.fields_for :educations construct (details here) is what you’re after for this. It will result in the right educations_attributes params arriving at your controller.

Hey Jason, that is correct. But when you are using a frontend framework you don’t get access to that and forcing Ember/Rails/[mvc framework] to do it in a rails way is more difficult than just transforming params on server side.

Then I think you should use a before_action in your controller(s). It’s really not the place of strong parameters to make adjustments to the parameter names.

Hello Austin. We’re using the Rails Resource library for AngularJS that does such things for us and happy with it (also it can convert attribute names from ruby’s snake_case to js camelCase). Look for similar library for your framework, may be it exists.