4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/watarase/generators/uploader/uploader_generator.rb', line 4
def create_image_holder
image_handler = file_name.camelcase.constantize
fk = image_handler.primary_key
fk_type = ((image_handler.respond_to? :columns) ? image_handler.columns.select{|column| column.name == fk}.first.type : :integer)
model_name = "#{file_name}_#{Watarase.suffix}"
str_code = <<-"CODE"
acts_as_image_holder
belongs_to :#{file_name}, primary_key: :#{fk}, foreign_key: :#{file_name}_#{fk}
CODE
generate "model", "#{model_name} #{file_name}_#{fk}:#{fk_type} filename:string content_type:string image_data:binary image_thumb:binary"
inject_into_class "app/models/#{model_name}.rb", model_name.camelcase.constantize do
str_code
end
end
|