Class: Comfy::Admin::Cms::FilesController
- Inherits:
-
BaseController
- Object
- BaseController
- Comfy::Admin::Cms::FilesController
- Defined in:
- app/controllers/comfy/admin/cms/files_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/comfy/admin/cms/files_controller.rb', line 34 def create @files = [] files = [file_params[:file]].flatten files.each_with_index do |file, i| label = (files.size > 1 && file_params[:label].present?) ? "#{file_params[:label]} #{i + 1}" : file_params[:label] @file = @site.files.create!(file_params.except(:file, :label).merge( :file => file, :label => label )) @files << @file end if params[:ajax] view = render_to_string(:partial => 'comfy/admin/cms/files/file', :collection => @files, :layout => false) render :json => {:filelink => @file.file.url, :filename => @file.file_file_name, :view => view.gsub("\n", '')} else flash[:success] = I18n.t('comfy.admin.cms.files.created') redirect_to :action => :edit, :id => @file end rescue ActiveRecord::RecordInvalid if params[:ajax] render :nothing => true, :status => :unprocessable_entity else flash.now[:danger] = I18n.t('comfy.admin.cms.files.creation_failure') render :action => :new end end |
#destroy ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/comfy/admin/cms/files_controller.rb', line 75 def destroy @file.destroy respond_to do |format| format.js format.html do flash[:success] = I18n.t('comfy.admin.cms.files.deleted') redirect_to :action => :index end end end |
#index ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/comfy/admin/cms/files_controller.rb', line 8 def index @files = @site.files.not_page_file.includes(:categories).for_category(params[:category]).order('comfy_cms_files.position') if params[:ajax] if params[:not_images] files = @files.not_images.collect do |file| { :label => file.label, :filename => file.file_file_name, :url => file.file.url } end else files = @files.images.collect do |file| { :thumb => file.file.url(:cms_thumb), :image => file.file.url } end end render :json => files else return redirect_to :action => :new if @site.files.count == 0 end end |
#new ⇒ Object
30 31 32 |
# File 'app/controllers/comfy/admin/cms/files_controller.rb', line 30 def new render end |
#reorder ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'app/controllers/comfy/admin/cms/files_controller.rb', line 86 def reorder (params[:comfy_cms_file] || []).each_with_index do |id, index| if (cms_file = ::Comfy::Cms::File.find_by_id(id)) cms_file.update_column(:position, index) end end render :nothing => true end |
#update ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'app/controllers/comfy/admin/cms/files_controller.rb', line 66 def update @file.update_attributes!(file_params) flash[:success] = I18n.t('comfy.admin.cms.files.updated') redirect_to :action => :edit, :id => @file rescue ActiveRecord::RecordInvalid flash.now[:danger] = I18n.t('comfy.admin.cms.files.update_failure') render :action => :edit end |