After_create is not being called

Hi all

I have the following model:

class PhotoGallery < ActiveRecord::Base
attr_accessible :title, :description, :file_path, :title_photo_id

has_many :photos, :dependent => :destroy
belongs_to :title_photo,
:class_name => ‘Photo’,
:foreign_key => ‘title_photo_id’

validates_presence_of :title, :description, :file_path

def after_validation
if !errors.invalid?(“file_path”)
images = get_images
if images.size == 0
errors.add_to_base(“There are no files in the directory
#{get_images_path}”)
else
errors.add_to_base(images.inspect)
end
end
rescue SystemCallError
errors.add_to_base(“The directory #{get_images_path} does not
exist”)
end

def after_create
if errors.empty?
get_images.each do |image|
photos.create :file => image.basename
end
end
raise =“asdfasdfasdfa”
end

some more stuff…

end

When I create a new photo gallery in the console, then after_validation
is being called without any problem, but after_create isn’t! I got no
idea why… :frowning:

Anyone has a clue? Thanks a lot.
Joshua

PS: I know, my Ruby style is still pretty bad… :wink:

Are you certain its getting created?

My gut reaction is that you have a before_create that is returning
false…

-hampton.

I finally figured it out. The line

if errors.empty?

seems to return false, and so nothing happens. I removed the if
statement, and now it works. Very strange although that the errors don’t
seem to be empty…?! :open_mouth:

And why didn’t the raise statement have any effect…?

Well, it works now, but I don’t really get it.