Class: Admin::PhotosController
- Inherits:
-
BaseController
- Object
- BaseController
- Admin::PhotosController
- Defined in:
- app/controllers/admin/photos_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/admin/photos_controller.rb', line 5 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 |
#destroy ⇒ Object
42 43 44 45 |
# File 'app/controllers/admin/photos_controller.rb', line 42 def destroy @photo.destroy respond_with(@photo) end |
#edit ⇒ Object
29 30 |
# File 'app/controllers/admin/photos_controller.rb', line 29 def edit end |
#search ⇒ Object
24 25 26 27 |
# File 'app/controllers/admin/photos_controller.rb', line 24 def search @photos = Photo.tagged_with(params[:q]).page(params[:page]) respond_with(@photos) end |
#update ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/admin/photos_controller.rb', line 32 def update @photo.attributes = params[:photo] @photo.save if request.format == "json" render :json => {:success => true} else respond_with(@photo) end end |