Skip to content

Breaking Change: hidden_field_tag for Nested Attributes Not Working After Upgrading to Rails 7 #3478

@aaronskiba

Description

@aaronskiba

Issue

After upgrading to Rails 7, we are encountering a breaking change related to the use of hidden_field_tag for nested attributes in forms. For example, the following code shows how repositories and metadata_standards associations were being set for research_output objects:

# app/views/research_outputs/metadata_standards/_search_result.html.erb %>
<%= hidden_field_tag "research_output[metadata_standards_attributes[#{result.id}][id]]", result.id %>
# app/views/research_outputs/repositories/_search_result.html.erb
<%= hidden_field_tag "research_output[repositories_attributes[#{result.id}][id]]", result.id %>
# app/models/research_output.rb
# Helper method to convert selected metadata standard form params into MetadataStandard objects
def metadata_standards_attributes=(params)
  params.each_value do |metadata_standard_params|
    metadata_standards << MetadataStandard.find_by(id: metadata_standard_params[:id])
  end
end

# Helper method to convert selected repository form params into Repository objects
def repositories_attributes=(params)
  params.each_value do |repository_params|
    repositories << Repository.find_by(id: repository_params[:id])
  end
end

However, neither the metadata_standards_attributes nor the repositories_attributes setters are being executed now. We are unable to set either of these associations when creating or updating a research_output. In fact, the update action within app/controllers/research_outputs_controller.rb includes the following code:

    # Clear any existing repository and metadata_standard selections.
    @research_output.repositories.clear
    @research_output.metadata_standards.clear

So not only are repositories or metadata_standards being saved when we update, but the existing ones are being deleted.

Necessary Steps

  • Update the args structure for the repositories and metadata_standards hidden_field_tag to comply with rails 7 requirements.
  • Investigate where similar breaking changes may exist with respect to the Rails 7 upgrade.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions