Class: CmsAdmin::SlidesController
- Inherits:
-
BaseController
- Object
- BaseController
- CmsAdmin::SlidesController
- Defined in:
- app/controllers/cms_admin/slides_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
26 27 28 29 30 31 32 33 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 |
# File 'app/controllers/cms_admin/slides_controller.rb', line 26 def create @slides = [] # Sometimes params[:file] comes in as a single file object unless params[:file].is_a?(Hash) uploaded_file = params[:file] params[:file] = { } params[:file][:file] = [uploaded_file] end file_array = params[:file][:file] || [nil] label = params[:file][:label] file_array.each_with_index do |file, i| file_params = params[:file].merge(:file => file) # if file_array.size > 1 && file_params[:label].present? # label = file_params[:label] + " #{i + 1}" # end @slide = @site..create!(file_params) @slides << @slide end if params[:ajax] view = render_to_string(:partial => 'cms_admin/slides/slide', :collection => @slides, :layout => false) render :json => {:filelink => @slide.file.url, :view => view.gsub("\n", '')} else flash[:success] = I18n.t('cms.slides.created') redirect_to :action => :index end rescue ActiveRecord::RecordInvalid logger.detailed_error($!) if params[:ajax] render :nothing => true, :status => :unprocessable_entity else flash.now[:error] = I18n.t('cms.slides.creation_failure') render :action => :new end end |
#destroy ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/cms_admin/slides_controller.rb', line 75 def destroy @slide.destroy respond_to do |format| format.js format.html do flash[:success] = I18n.t('cms.slides.deleted') redirect_to :action => :index end end end |
#index ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/cms_admin/slides_controller.rb', line 8 def index @slides = @site..order('cms_slides.position') if params[:ajax] = @slides.images.collect do || { :thumb => .file.url(:cms_thumb), :image => .file.url } end render :json => else return redirect_to :action => :new if @site..count == 0 end end |
#new ⇒ Object
22 23 24 |
# File 'app/controllers/cms_admin/slides_controller.rb', line 22 def new render end |
#reorder ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'app/controllers/cms_admin/slides_controller.rb', line 86 def reorder (params[:cms_slide] || []).each_with_index do |id, index| if ( = Cms::Slide.find_by_id(id)) .update_attributes(:position => index) end end render :nothing => true end |
#update ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/cms_admin/slides_controller.rb', line 65 def update @slide.update_attributes!(params[:file]) flash[:success] = I18n.t('cms.slides.updated') redirect_to :action => :edit, :id => @slide rescue ActiveRecord::RecordInvalid logger.detailed_error($!) flash.now[:error] = I18n.t('cms.slides.update_failure') render :action => :edit end |