Displaying 2 results from an estimated 2 matches for "create_image".
2006 Jul 22
7
Validation with has_many
I have two problems. I have a comment that has_many uploads. Before
saving the comment, I want to be sure that the upload(s) has passed
validation, but I also need to validate in other ways. For example, I
do not want to save the comment if there is no comment or upload. Or, I
do not want to save the comment if the image has been uploaded
previously (comparing md5s with past upload md5s
2006 Jul 25
1
How do I validate using associated objects?
...Strangely, I can access uploads from the
Comment model.
This is frustrating the hell out of me :(
class Comment < ActiveRecord::Base
belongs_to :board
has_many :uploads
end
class Upload < ActiveRecord::Base
belongs_to :comment
end
class Image < Upload
before_create :create_image
before_create :create_thumbnail
def create_image
@image = Magick::ImageList.new.from_blob(@upload_blob)
self[:image_width] = @image.columns
self[:image_height] = @image.rows
end
def create_thumbnail
@thumbnail = Magick::ImageList.new.from_blob(@image[0].to_blob)...