I am using fleximage to handle images. Its great. I can upload, edit and view the image just fine. But, now I want to allow users to delete their image. Can someone please explain how. In the UI when a user is editing the model with the image, currently I display the image and give users the option to upload a new file. I am changing it so that a user selects to either keep the image, upload a new image or clear their image. In the controller I check if the clear image param was passed in and then delete the image from the table. I have tried: @mod.data = nil this returns the error: Exception in edit_module: You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occured while evaluating nil.size It looks like it is trying to resize the image which is now nil. Also tried: @mod.data = '' '' This didn''t do anything I am all ears on how to delete the image. Thanks. Model ----------- class LibResource < FlexImage::Model self.require_image_data = false pre_process_image :size => ''250x250'' Controller -------------- if request.post? @mod.attributes = params[:mod] #updates the model as usual .... if params[:image_options] option = params[:image_options] if option == ''Remove my image'' @mod.data = nil @mod.save! end end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bump. Anyone ever had to delete a fleximage form the table. Tell me how you did it. On Aug 24, 3:53 pm, Kim <Kim.Gri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am using fleximage to handle images. Its great. I can upload, edit > and view the image just fine. But, now I want to allow users to delete > their image. Can someone please explain how. > > In the UI when a user is editing the model with the image, currently I > display the image and give users the option to upload a new file. I am > changing it so that a user selects to either keep the image, upload a > new image or clear their image. In the controller I check if the clear > image param was passed in and then delete the image from the table. > I have tried: > @mod.data = nil > this returns the error: > Exception in edit_module: You have a nil object when you didn''t expect > it! > You might have expected an instance of Array. > The error occured while evaluating nil.size > > It looks like it is trying to resize the image which is now nil. > > Also tried: > > @mod.data = '' '' > This didn''t do anything > > I am all ears on how to delete the image. Thanks. > > Model > ----------- > class LibResource < FlexImage::Model > self.require_image_data = false > pre_process_image :size => ''250x250'' > > Controller > -------------- > if request.post? > @mod.attributes = params[:mod] #updates the model as usual > > .... > if params[:image_options] > option = params[:image_options] > if option == ''Remove my image'' > @mod.data = nil > @mod.save! > end > end--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hey Kim, I am by no means a rails expert, so there''s probably a dozen things wrong with my code, but it at least works. Here''s how I delete my fleximage pictures from both the database and the filesystem: In my view, I have a checkbox for each image, named "photo_delete" and having the values of the table id for that image. So params[:photo_delete] is a hash of all the id''s of the images the user wants to delete. Then, in my controller: @delete = Photo.find(:all, :conditions => { :id => params[:photo_delete] }) if params[:photo_delete] if @delete @delete.each do |delete| #----------------------Clean this up to automatically get the photo extension type----------------------------------- File.delete("#{RAILS_ROOT}/public/images/#{delete.id}.jpg") @message = "Photos have been deleted. " if delete.destroy end I hope this helps with what you are trying to do. On Aug 25, 6:41 pm, Kim <Kim.Gri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Bump. Anyone ever had to delete a fleximage form the table. Tell me > how you did it. > > On Aug 24, 3:53 pm, Kim <Kim.Gri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I am using fleximage to handle images. Its great. I can upload, edit > > and view the image just fine. But, now I want to allow users to delete > > their image. Can someone please explain how. > > > In the UI when a user is editing the model with the image, currently I > > display the image and give users the option to upload a new file. I am > > changing it so that a user selects to either keep the image, upload a > > new image or clear their image. In the controller I check if the clear > > image param was passed in and then delete the image from the table. > > I have tried: > > @mod.data = nil > > this returns the error: > > Exception in edit_module: You have a nil object when you didn''t expect > > it! > > You might have expected an instance of Array. > > The error occured while evaluating nil.size > > > It looks like it is trying to resize the image which is now nil. > > > Also tried: > > > @mod.data = '' '' > > This didn''t do anything > > > I am all ears on how to delete the image. Thanks. > > > Model > > ----------- > > class LibResource < FlexImage::Model > > self.require_image_data = false > > pre_process_image :size => ''250x250'' > > > Controller > > -------------- > > if request.post? > > @mod.attributes = params[:mod] #updates the model as usual > > > .... > > if params[:image_options] > > option = params[:image_options] > > if option == ''Remove my image'' > > @mod.data = nil > > @mod.save! > > end > > end--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
And, uh, try to ignore the line-breaks in the code that were automatically added to my post. On Sep 2, 11:24 pm, No BS <schwartz.st...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey Kim, > > I am by no means a rails expert, so there''s probably a dozen things > wrong with my code, but it at least works. Here''s how I delete my > fleximage pictures from both the database and the filesystem: > > In my view, I have a checkbox for each image, named "photo_delete" and > having the values of the table id for that image. So > params[:photo_delete] is a hash of all the id''s of the images the user > wants to delete. > > Then, in my controller: > > @delete = Photo.find(:all, :conditions => { :id => > params[:photo_delete] }) if params[:photo_delete] > if @delete > @delete.each do |delete| > #----------------------Clean this up to automatically get the photo > extension type----------------------------------- > File.delete("#{RAILS_ROOT}/public/images/#{delete.id}.jpg") > @message = "Photos have been deleted. " if delete.destroy > end > > I hope this helps with what you are trying to do. > > On Aug 25, 6:41 pm, Kim <Kim.Gri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Bump. Anyone ever had to delete a fleximage form the table. Tell me > > how you did it. > > > On Aug 24, 3:53 pm, Kim <Kim.Gri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I am using fleximage to handle images. Its great. I can upload, edit > > > and view the image just fine. But, now I want to allow users to delete > > > their image. Can someone please explain how. > > > > In the UI when a user is editing the model with the image, currently I > > > display the image and give users the option to upload a new file. I am > > > changing it so that a user selects to either keep the image, upload a > > > new image or clear their image. In the controller I check if the clear > > > image param was passed in and then delete the image from the table. > > > I have tried: > > > @mod.data = nil > > > this returns the error: > > > Exception in edit_module: You have a nil object when you didn''t expect > > > it! > > > You might have expected an instance of Array. > > > The error occured while evaluating nil.size > > > > It looks like it is trying to resize the image which is now nil. > > > > Also tried: > > > > @mod.data = '' '' > > > This didn''t do anything > > > > I am all ears on how to delete the image. Thanks. > > > > Model > > > ----------- > > > class LibResource < FlexImage::Model > > > self.require_image_data = false > > > pre_process_image :size => ''250x250'' > > > > Controller > > > -------------- > > > if request.post? > > > @mod.attributes = params[:mod] #updates the model as usual > > > > .... > > > if params[:image_options] > > > option = params[:image_options] > > > if option == ''Remove my image'' > > > @mod.data = nil > > > @mod.save! > > > end > > > end--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---