
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
accepts_nested_attributes_for_public_id
Advanced tools
A patch for Rails to support using a public ID column instead of ID for use with accepts_nested_attributes_for
Supports Rails 5, 6, 7+
Why:
accepts_nested_attributes_for does not respect to_param or provide any ability to utilize a public ID column. This results in your DB primary keys being exposed in your forms.gem 'accepts_nested_attributes_for_public_id'
You now have access to the following options:
class Post < ApplicationRecord
has_many :comments
accepts_nested_attributes_for :comments
end
class Comment < ApplicationRecord
belongs_to :post
def self.accepts_nested_attributes_for_public_id_column
:my_public_id_db_column
end
end
class Post < ApplicationRecord
has_many :comments
accepts_nested_attributes_for :comments, public_id_column: :my_public_id_db_column
end
class Comment < ApplicationRecord
belongs_to :post
end
The code for Nested Attributes in Rails core has not changed since around Rails 4 (Rails 7.0 is the current release at the time of writing this)
Because this patch requires changes in the very middle of some larger sized methods we are unable to use super in the patches. This can make it fragile if new changes were introduced to Rails core.
We have taken steps to ensure that no issues are caused by any future Rails changes by adding runtime contracts that ensure the original method source matches our saved contract of the current sources of these methods. If a new Rails version were to change the original method source then you would receive a runtime error stating that we are unable to apply the patch until the gem has been made compatible with any changed code.
RAILS_ENV=test bundle exec rake db:create
RAILS_ENV=test bundle exec rake db:migrate
bundle exec rspec
We can locally test different versions of Rails using ENV['RAILS_VERSION'] and different database gems using ENV['DB_GEM']
export RAILS_VERSION=7.0
export DB_GEM=sqlite3
bundle install
bundle exec rspec
Created & Maintained by Weston Ganger - @westonganger
FAQs
Unknown package
We found that accepts_nested_attributes_for_public_id demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.