Skip to content

Instantly share code, notes, and snippets.

@andrellima
Created March 24, 2011 13:28
Show Gist options
  • Save andrellima/885043 to your computer and use it in GitHub Desktop.
Save andrellima/885043 to your computer and use it in GitHub Desktop.
class GalleriesController < ApplicationController
# GET /galleries
# GET /galleries.xml
def index
@galleries = Gallery.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @galleries }
end
end
# GET /galleries/1
# GET /galleries/1.xml
def show
@gallery = Gallery.find(params[:id])
gallery_photo = GalleryPhoto.new
gallery_photo = GalleryPhoto.find(:all, :conditions => {:gallery_id => @gallery.id})
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @gallery }
end
end
# GET /galleries/new
# GET /galleries/new.xml
def new
@gallery = Gallery.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @gallery }
end
end
# GET /galleries/1/edit
def edit
@gallery = Gallery.find(params[:id])
end
# POST /galleries
# POST /galleries.xml
def create
['photo_01', 'photo_02', 'photo_03', 'photo_04', 'photo_05', 'photo_06'].each do |p|
unless params[:gallery_photos][p].nil?
gallery_photo = GalleryPhoto.new
gallery_photo = params[:gallery_photo][p]
gallery_photo.gallery_id = params[:gallery_photo]['gallery_id']
gallery_photo.save
end
end
redirect_to :controller => 'galleries', :action => 'show', :id => params[:gallery_photos]['gallery_id']
respond_to do |format|
if @gallery.save
format.html { redirect_to(@gallery, :notice => 'Gallery was successfully created.') }
format.xml { render :xml => @gallery, :status => :created, :location => @gallery }
else
format.html { render :action => "new" }
format.xml { render :xml => @gallery.errors, :status => :unprocessable_entity }
end
end
end
# PUT /galleries/1
# PUT /galleries/1.xml
def update
@gallery = Gallery.find(params[:id])
respond_to do |format|
if @gallery.update_attributes(params[:gallery])
format.html { redirect_to(@gallery, :notice => 'Gallery was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @gallery.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /galleries/1
# DELETE /galleries/1.xml
def destroy
@gallery = Gallery.find(params[:id])
@gallery.destroy
respond_to do |format|
format.html { redirect_to(galleries_url) }
format.xml { head :ok }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment