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…
Anyone has a clue? Thanks a lot.
Joshua
PS: I know, my Ruby style is still pretty bad…