Class: Grandstand::ImagesController

Inherits:
MainController
  • Object
show all
Defined in:
app/controllers/grandstand/images_controller.rb

Instance Method Summary collapse

Methods inherited from MainController

#expand

Instance Method Details

#createObject

session :cookies_only => false, :only => :create



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/grandstand/images_controller.rb', line 7

def create
  @image = @gallery.images.new(params[:image])
  if @image.save
    if params.has_key?('Filename') || request.xhr?
      render(:json => {:status => :ok})
    else
      flash[:success] = 'Your image was successfully uploaded'
      redirect_to(grandstand_gallery_path(@gallery))
    end
  else
    render :new
  end
end

#deleteObject



21
22
# File 'app/controllers/grandstand/images_controller.rb', line 21

def delete
end

#destroyObject



24
25
26
27
28
# File 'app/controllers/grandstand/images_controller.rb', line 24

def destroy
  @image.destroy
  flash[:delete] = 'Your image has been deleted'
  redirect_to grandstand_gallery_path(@gallery)
end

#editObject



30
31
32
# File 'app/controllers/grandstand/images_controller.rb', line 30

def edit
  @image = @gallery.images.find(params[:id])
end

#indexObject



34
35
36
# File 'app/controllers/grandstand/images_controller.rb', line 34

def index
  redirect_to grandstand_gallery_path(@gallery)
end

#newObject



38
39
40
# File 'app/controllers/grandstand/images_controller.rb', line 38

def new
  @image = Grandstand::Image.new
end

#reorderObject



42
43
44
45
46
47
# File 'app/controllers/grandstand/images_controller.rb', line 42

def reorder
  params[:images].each_with_index do |image_id, index|
    @gallery.images.update(image_id, :position => index + 1)
  end if params[:images]
  render :json => {:status => :ok}
end

#updateObject



49
50
51
52
53
54
55
56
# File 'app/controllers/grandstand/images_controller.rb', line 49

def update
  if @image.update_attributes(params[:image])
    flash[:success] = 'Your image was successfully saved'
    request.xhr? ? render(:json => {:status => :ok}) : redirect_to(grandstand_gallery_path(@gallery))
  else
    render :new
  end
end

#uploadObject



59
60
# File 'app/controllers/grandstand/images_controller.rb', line 59

def upload
end