You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simbul edited this page Jun 26, 2012
·
2 revisions
If you have problems with a model with accept_nested_attributes_for, you should check how your parent model deals with validation of its child model. For example, something like this should work (assuming Plant is the parent model and Photo is its child):
classPlant < ActiveRecord::Base# validations, associations and so on...has_many:photosaccepts_nested_attributes_for:photo, \
:reject_if=>proc{|attributes| attributes['filename'].blank? \
&& attributes['filename_cache'].blank?}endclassPhoto < ActiveRecord::Baseattr_accessible:cover,:title,:filename,:filename_cachebelongs_to:plantmount_uploader:filename,PhotoUploaderend
If something is still wrong, keep in mind that after a redisplay :filename is empty, while :filename_cache should contain a string value: trying to validate the presence of :filename would cause an error, preventing Rails to save models into your database.