ActiveScaffold :: Wiki
Active Scaffold with Attachment_fu

In this example we construct one app that use Active Scaffold and Attachment_fu in conjuntion.

We have two objects: Person that will have multiple Images.

/app/model/person.rb :

class Person < ActiveRecord::Base
 has_many :images
 def uploaded_data
   nil
 end
 def uploaded_data=(data)
   self.images<< Image.new(:uploaded_data => data)
 end
end

/app/model/image.rb :

class Image < ActiveRecord::Base
 has_attachment :content_type => :image,
                :storage => :file_system,
                :max_size => 5500.kilobytes,
                :resize_to => '320x200>',
                :thumbnails => { :thumb => '150x100>' },
                :path_prefix => 'public/uploads',
                :content_type => :image
  validates_as_attachment
  belongs_to :person
end

The uploaded images will be saved in public/uploads directory.

We will construct two controllers: images and person. The person controller will use the images controller as nested list.

class PersonController < ApplicationController
       active_scaffold :person do |config|
   config.columns.add :uploaded_data
   config.create.multipart = true
   config.create.columns = [:uploaded_data, :name]
   config.nested.add_link("Images", [:images])
 end
end
module PersonHelper
 def uploaded_data_form_column(record,input_name)
   file_field_tag input_name[:name]
 end
end
class ImagesController < ApplicationController
 active_scaffold :image do |config|
  config.columns.add :uploaded_data
  config.create.multipart = true
  config.create.columns = [:uploaded_data]
  config.list.columns = [:filename, :image]
 end
end

With the config.list.columns in the images controller we will list only two columns: the filename and an “image column” that we will use to show the image with this helper:

module ImagesHelper
 def image_column(record)
   image_tag record.public_filename(:thumb)
 end
end