Rails 3: How does “accepts_nested_attributes_for” work?

I think that you’re trying to figure out creating a new associated item vs. associating with an existing item. For creating a new item, you seem to have it working. When you passed the id in shop_attributes, it did not work, because it’s looking up an association that doesn’t exist yet. If you’re trying to … Read more

accepts_nested_attributes_for with belongs_to polymorphic

I’ve also had a problem with the “ArgumentError: Cannot build association model_name. Are you trying to build a polymorphic one-to-one association?” And I found a better solution for this kind of problem. You can use native method. Lets look to the nested_attributes implementation, inside Rails3: elsif !reject_new_record?(association_name, attributes) method = “build_#{association_name}” if respond_to?(method) send(method, attributes.except(*UNASSIGNABLE_KEYS)) … Read more

RoR nested attributes produces duplicates when edit

I had to add :id to the permitted params in the survey_params method. It now looks like this: # Never trust parameters from the scary internet, only allow the white list through. def survey_params params.require(:survey).permit(:name, questions_attributes: [:id, :content]) end which works perfectly. I guess new id’s were generated instead of being passed to the update … Read more

Rails – Strong Parameters – Nested Objects

As odd as it sound when you want to permit nested attributes you do specify the attributes of nested object within an array. In your case it would be Update as suggested by @RafaelOliveira params.require(:measurement) .permit(:name, :groundtruth => [:type, :coordinates => []]) On the other hand if you want nested of multiple objects then you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)