I've been playing around with Rails 4 and having some issues updating a record with strong parameters. I keep getting a "Stack Level Too Deep" error. I'm trying to update a post record that has_one meta_data.
post.rb
has_one :meta_data, :as => :meta_dataeable, :dependent => :destroy
accepts_nested_attributes_for :meta_data
after_initialize do
self.build_meta_data unless self.meta_data.present?
end
posts_controller.rb
def create
@post = Post.create(permitted_params)
redirect_to :action => 'index'
end
def update
@post = Post.find(params[:id])
@post.update_attributes(permitted_params)
redirect_to :action => 'index'
end
def permitted_params
params.require(:post).permit(
:title,
:body,
:excerpt,
:permalink,
:content_type,
:author_id,
:media,
:commenting,
:published_at,
:public,
{:meta_data_attributes => [:title, :description, :keywords, :menu_name]}
)
end
Creating a new record works without any problems and saves the associated meta_data record. Updating gives me a Stack Level Too Deep error. When I remove the {:meta_data_attributes => [:title, :description, :keywords, :menu_name]}
from my permitted params, saving works without a problem
Any help would be great, thank you in advance!
Figured out the problem, need to add :id
as a permitted parameter for the meta_data_attributes.