image class with attributes

This commit is contained in:
2022-11-28 00:12:20 +02:00
parent 4814f53d1e
commit 76b29123a6
3 changed files with 56 additions and 27 deletions

View File

@ -2,32 +2,18 @@ module Cms
class ImagesController < CmsController
@@root = "app/assets/images/cms/"
@@files = Set.new Dir[Rails.root + @@root + "*.*"].collect{|f|f.split("/").last}
def index
@files = files
@images = Image.all
end
def new
end
def create
io = params['image_file']
ending = io.original_filename.split("/").last.split(".").last
filename = params['filename'] + "." + ending
File.open(Rails.root.join('app/assets/images/cms', filename), "wb") do |f|
f.write io.read
end
@@files << filename
Image.save_image(params['filename'] , params['image_file'])
redirect_to cms_image_index_path
end
private
def files
@@files
end
end
end