photomix/app/controllers/photos_controller.rb

92 lines
2.5 KiB
Ruby
Raw Normal View History

2009-05-22 14:13:46 +02:00
class PhotosController < ApplicationController
2009-05-22 21:04:41 +02:00
before_filter :require_user, :only => [:new, :create, :edit, :update, :destroy]
def index
2009-06-02 00:08:57 +02:00
if params[:tag_id]
@photos = Tag.find_by_title( params[:tag_id] ).photos
elsif params[:q]
@photos = Photo.find(:all, :limit => 20, :conditions => [ "Photos.description LIKE :q OR Photos.title LIKE :q OR Photos.Id IN ( SELECT Photo_Id FROM Photo_Tags LEFT OUTER JOIN Tags ON Photo_Tags.Tag_Id = Tags.Id WHERE Tags.Title LIKE :q) ", { :q => '%' + params[:q] + '%' } ], :include => :album )
else
@photos = Photo.find(:all, :limit => 20)
end
respond_to do |format|
format.html
format.json { render :json => @photos }
format.xml { render :xml => @photos }
end
end
def untouched
@photos = Photo.untouched()
2009-05-22 21:04:41 +02:00
respond_to do |format|
format.html
format.json { render :json => @photos }
format.xml { render :xml => @photos }
end
end
def show
@photo = Photo.find( params[:id])
respond_to do |format|
format.html
format.json { render :json => @photo }
format.xml { render :xml => @photo }
end
end
def new
@photo = Photo.new
end
def create
2009-06-02 00:08:57 +02:00
respond_to do |format|
@photo = Photo.new(params[:photo])
if params[:Filedata]
@photo.swf_uploaded_data = params[:Filedata]
2009-06-03 01:33:39 +02:00
if @photo.save
format.html { render :text => "FILEID:" + @photo.path_modified_public("album") }
format.xml { render :nothing => true }
else
format.html { render :text => "ERRORS:" + @photo.errors.full_messages.join(" "), :status => 500 }
format.xml { render :xml => @photo.errors, :status => 500 }
end
2009-06-02 00:08:57 +02:00
else
if @photo.save
flash[:notice] = 'Created'
format.html { redirect_to(@photo) }
format.xml { render :xml => @photo }
else
format.html { render :action => "new" }
format.xml { render :xml => @photo.errors }
end
end
2009-05-22 21:04:41 +02:00
end
end
def edit
@photo = Photo.find( params[:id])
end
def update
@photo = Photo.find( params[:id])
if @photo.update_attributes(params[:photo])
flash[:notice] = "Account updated!"
redirect_to @photo
else
render :action => :edit
end
end
2009-06-02 00:08:57 +02:00
def destroy
2009-05-22 21:04:41 +02:00
@photo = Photo.find( params[:id])
2009-06-02 00:08:57 +02:00
@album = @photo.album
if @photo.destroy
redirect_to @album
2009-05-22 21:04:41 +02:00
else
redirect_to @photo
end
end
2009-05-22 14:13:46 +02:00
end