Rails: accepts_nested_attributes_for with "strong parameters" requiring identifiers in parameters
Suppose the model Book
, with:
class Book < ActiveRecord::Base
has_many: pages
accepts_nested_attributes_for :pages
To UPDATE a record Page
instead of CREATING a new one, Rails requires the nested model ID (here:) Page
to resolve in "strong parameters" (instance Book
):
def update
@book.update(book_params)
end
private
def book_params()
params.require(:book).permit(:title, :author, :published,
pages_attributes: [:id, :word_count, :line_count]) # <= this ID in here
end
But does the inclusion ID
of "strong parameters" mean their goal? (Meaning: The user may submit false ID
, causing an invalid connection.)
+3
source to share