class Admin::PhotosController < Admin::BaseController respond_to :html, :js layout false def create photographable_id = params[:photographable_id] photographable_class = params[:photographable_type].constantize @photographable = photographable_class.find(photographable_id) if @photographable.respond_to?(:photos) # <- has_many :photos @photo = @photographable.photos.build({:image => params[:file]}) else # <- has_one :photo @photo = @photographable.build_photo({:image => params[:file]}) end if @photo.save respond_with(@photo) else render :status => 500 end end def search @photos = Photo.tagged_with(params[:q]).page(params[:page]) respond_with(@photos) end def edit end def update @photo.attributes = params[:photo] @photo.save respond_with(@photo) end def destroy @photo.destroy respond_with(@photo) end end