Class: Admin::PhotosController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::PhotosController
- Includes:
- RespondsToParent
- Defined in:
- app/controllers/admin/photos_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #mass_destroy ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/admin/photos_controller.rb', line 25 def create photo_file = photo_params[:photo] if photo_file.present? fingerprint = Digest::MD5.hexdigest(photo_file.read) photo_file.rewind @photo = SpudPhoto.where(:photo_fingerprint => fingerprint).first end if @photo.blank? @photo = SpudPhoto.new(photo_params) end if @photo.save success = true flash[:notice] = 'SpudPhoto created successfully' end if request.xhr? render json_for_photo(success) else respond_to_parent do render 'show.js' end end end |
#destroy ⇒ Object
71 72 73 74 |
# File 'app/controllers/admin/photos_controller.rb', line 71 def destroy flash[:notice] = 'SpudPhoto deleted successfully' if @photo.destroy respond_with @photo, :location => admin_photos_path end |
#edit ⇒ Object
50 51 52 53 54 |
# File 'app/controllers/admin/photos_controller.rb', line 50 def edit respond_with @photo do |format| format.js { render 'edit', :layout => false } end end |
#index ⇒ Object
9 10 11 12 |
# File 'app/controllers/admin/photos_controller.rb', line 9 def index @photos = SpudPhoto.all respond_with @photos end |
#mass_destroy ⇒ Object
76 77 78 79 80 |
# File 'app/controllers/admin/photos_controller.rb', line 76 def mass_destroy @photos = SpudPhoto.where(:id => params[:spud_photo_ids]) flash[:notice] = 'Photos deleted successfully' if @photos.destroy_all respond_with @photos, :location => admin_photos_path end |
#new ⇒ Object
18 19 20 21 22 23 |
# File 'app/controllers/admin/photos_controller.rb', line 18 def new @photo = SpudPhoto.new respond_with @photo do |format| format.js { render 'new', :layout => false } end end |
#show ⇒ Object
14 15 16 |
# File 'app/controllers/admin/photos_controller.rb', line 14 def show respond_with @photo end |
#update ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/admin/photos_controller.rb', line 56 def update @photo.update_attributes(photo_params) if @photo.save success = true flash[:notice] = 'SpudPhoto updated successfully' end if request.xhr? render json_for_photo(success) else respond_to_parent do render 'show.js' end end end |