class Admin::ImagesController < Admin::ApplicationController def create @object = find_object @image = @object.images.build(params[:image]) if @image.save flash[:notice] = "The image was successfully added." else flash[:error] = "There was an error adding the image." end redirect_to [:admin, @object] end def new case @request.method when :post params[:image].each_with_index do |image, name| end # render :text => params[:photo].inspect end end def sort Image.order(params[:image]) render :nothing => true end def update_positions params[:images].each_with_index do |id, position| Image.update(id, :position => position) end render :nothing => true end def update_description @image = Image.find(params[:id]) @image.update_attributes(params[:image]) render(:partial => "shared/image", :object => @image, :layout => false) end def add_image @image = Image.new(params[:image]) if @image.save if @image.item_id redirect_to :controller => 'items', :action => 'show', :id => @image.item_id else redirect_to :controller => 'auctions', :action => 'item', :id => @image.auction_item_id end end end def destroy @image = Image.find(params[:id]) if @image.destroy flash[:notice] = "The image has been deleted." else flash[:error] = "The image could not be deleted." end redirect_to :back end private def find_object params.each do |name, value| if name =~ /(.+)_id$/ return $1.classify.constantize.find(value) end end nil end end