Integrating File Column Plugin in Active Scaffold is very easy
Assuming File Column Plugin is installed in your application.
In controller we need to write the following code to make it work:
Considering there is a field called Product_Image in product
active_scaffold :product do |config|
config.label = "Product Page"
config.columns = [:product_name, :product_description, :product_image]
config.create.multipart = true
config.update.multipart = true
config.columns[:product_image].label = "Product Image"
end
Its not yet done we need to do few coding in helper and model also
In Product_Helper.rb we need to add the following code
def product_image_form_column(record, input_name)
file_column_field 'record', :product_image, :onkeypress=>"return numbersonly(event, false)"
end
#onkeypress event is used to advoid typing characters in file field
def product_image_column(record)
image_tag url_for_file_column(record, "product_image") if record.product_image
end
and In Product_Image.rb we need to write a single line code
file_column :product_image
Its Done and when you upload a image it will create that image in a folder named by the Product_id in public/Product_images and will insert the image name in product_image product table
No comments:
Post a Comment