Class: Grandstand::GalleriesController
- Inherits:
-
MainController
- Object
- ApplicationController
- MainController
- Grandstand::GalleriesController
- Defined in:
- app/controllers/grandstand/galleries_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #reorder ⇒ Object
- #update ⇒ Object
Methods inherited from MainController
Instance Method Details
#create ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/grandstand/galleries_controller.rb', line 4 def create @gallery = Grandstand::Gallery.new(params[:gallery].merge(:user => current_user)) if @gallery.save flash[:success] = "#{@gallery.name} was successfully added" redirect_to grandstand_gallery_path(@gallery) else flash[:error] = 'There was a problem creating this gallery' render :new end end |
#delete ⇒ Object
15 16 17 18 19 20 |
# File 'app/controllers/grandstand/galleries_controller.rb', line 15 def delete unless @gallery.published? flash[:error] = 'You cannot delete this gallery. It is required by the system.' redirect_to return_path || grandstand_galleries_path end end |
#destroy ⇒ Object
22 23 24 25 26 |
# File 'app/controllers/grandstand/galleries_controller.rb', line 22 def destroy @gallery.destroy flash[:delete] = 'Your gallery has been deleted' redirect_to grandstand_galleries_path end |
#index ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/controllers/grandstand/galleries_controller.rb', line 28 def index if request.xhr? @galleries = Grandstand::Gallery.all render :editor else @galleries = Grandstand::Gallery.where(:published => true).all end end |
#new ⇒ Object
37 38 39 |
# File 'app/controllers/grandstand/galleries_controller.rb', line 37 def new @gallery = Grandstand::Gallery.new end |
#reorder ⇒ Object
41 42 43 44 45 46 |
# File 'app/controllers/grandstand/galleries_controller.rb', line 41 def reorder params[:galleries].each_with_index do |gallery_id, index| Grandstand::Gallery.update(gallery_id, :position => index + 1) end if params[:galleries] render :json => {:status => :ok} end |
#update ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/grandstand/galleries_controller.rb', line 48 def update if @gallery.update_attributes(params[:gallery]) flash[:success] = "#{@gallery.name} was successfully saved" request.xhr? ? render(:json => {:status => :ok}) : redirect_to(grandstand_gallery_path(@gallery)) else flash[:error] = 'There was a problem saving this gallery' render :edit end end |