I have a nested form problem. I implemented the nested forms solution form the railscasts 196 & 197. It works if I have no validation errors.
So, form renders pe
at this moment, the only way i find to fix that it was only overwriting the create method.
def new
@property = Property.new
@property.images.build
end
def create
@property = Property.new(params[:property])
if @property.save
flash[:success] = t('Your_property') + ' ' + t('is_successfully_created')
redirect_to myimmonatie_url
else
@property.images.build if @property.images.blank? ##because i'm shure you have something similar to : accepts_nested_attributes_for :images, :reject_if => lambda { |fields| fields[:image].blank? }
render :action => 'new'
end
end
hope it helps!
I was also having the same problem with this behavior. Since I can't see your model, my guess is that you have :reject_if => :all_blank or some other lambda. This seems to be the culprit, although I don't have a fix. I would leave this as a comment instead of answer, but apparently I don't have enough reputation to do such a thing.
Does it throw an error?
My guess is your problem is that in your new
action, you are doing @property.images.build
, which is not in your edit action. When the validation fails, it will render your new action, but won't run your new action. You could try putting @property.images.build
in the else clause of your create
action like:
else
@property.images.build
render :action => 'new'
end
Not the cleanest way to do it, by any means, but this will help track down if that is your issue.