defnew@photo = Photo.new(params[:photo])
end# Create a new Photo. e.g. [POST] /gallery/photos
## +photo+:: A hash of attributes to set for the new photo object,
# e.g. ?photo[title]=Father&photo[body]=Dad&photo[parent_id]=2
# Returns HTTP status "201 Created" if successful.
# When params[:diecut_for] is set, redirects to diecut page
defcreate@photo = Photo.new(params[:photo])
if@photo.send(:filename_state).class == FileColumn::NoUploadedFile
flash[:warning] = "Nothing uploaded"redirect_to:action => "new"andreturnend@photo.save!
# Add to book, if context exists
@photo.books << @bookif@book
respond_to do |format|
# format.js # renders create.rjs
format.html {redirect_to edit_photo_url(:id => @photo.content_id) }
format.xml do
headers["Location"] = photo_url(:id => @photo.content_id)
render(:nothing => true, :status => "201 Created")
endendend# Reveal photo data such as caption
# +id+:: The id of the Photo object to show. e.g. [GET] /gallery/photos/6
# Returns the photo in HTML or XML.
defshow@version = params["version"] || "small"
respond_to do |format|
# format.js # renders show.rjs
format.html # renders show.rhtml
format.xml {render:xml => @photo.to_xml }
endenddefedit# If we're in a book context, try to add the book's cone(s) to this photo as a default
if@photo.content_pointer.cones.count == 0@photo.content_pointer.copy_cones(@book.content_pointer.cones)
@photo.content_pointer.save!
end
respond_to do |format|
# format.js # renders edit.rjs
format.html # renders edit.rhtml
format.xml {render:xml => @photo.to_xml }
endend# Change photo attributes
# +id+:: The id of the Photo object to show. e.g. [PUT] /gallery/photos/6
# +photo+:: A hash of attributes to update, e.g. ?photo[caption]=Father...
# Returns the updated Photo in XML or redirects to a page that shows the photo in HTML.
defupdate@photo.attributes = params[:photo]
@photo.cone_data = params[:cones]
@photo.save!
respond_to do |format|
# format.js # renders update.rjs
format.html do
flash[:notice] = "Photo updated"redirect_to photos_url
end
format.xml {render:xml => @photo.to_xml }
endend# Send a Photo to the trash bin
# +id+:: The id of the Photo object to trash. e.g. [DELETE] /gallery/photos/6
defdestroyif params[:warn]
@books = @photo.occurrences.map {|o| o.book }.compact
render:action => "destroy_with_warning"returnend@photo.trash
respond_to do |format|
format.html do
flash[:notice] = "Photo removed"redirect_to photos_url
end
format.xml {render:nothing => true }
endend