Using Strong Parameters With Fields for & Nested Forms in Rails 4
With strong_parameters becoming the standard way of handling security in Rails 4, I played around with it. It works great except the documentation isn’t clear on how to handle nested forms inside Rails, specifically with the accepts_nested_attributes_for in the model and fields_for in views.
So far so good, let take a look a short example below.
classAccountsController<ApplicationControllerdefnew@account=Account.new@account.people.buildenddefcreate@account=Account.new(new_account_params)if@account.saverespond_todo|format|format.html{redirect_toroot_path,notice:"Account created successfully."}endendendprivatedefnew_account_paramsparams.require(:account).permit(:id,:name,people_attributes:[:id,:email,:password,:password_confirmation])endend