Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
image deleting from file
4 Posts
image deleting from file

can any one help deleting image(which is uploaded to public/profile image folder)rom file.

                              mohd anas

File.delete(filename, ...) is the function you need.

Try File.delete("#{RAILS_ROOT}/public/profile image folder/#{filename}")

Another trick I am very partial to in Ruby is the ability to run bash commands dynamically. So you could also use backticks like so:

rm #{RAILS_ROOT}/public/profile image folder/#{filename}

Of course this kind of thing will break on Windows, but sorry, Windows isn't a proper development or deployment platform, we have been saying it since people wanted to compile and host MUDs on their Windows boxes.

Person
Sr. Ruby & Rails Consultant For Hire
Sign In To Rate Post

James, try to use backticks with filename = ' || rm -rf /' ;)

to be platform independent use File.delete and File.join: File.delete( File.join(RAILS_ROOT, 'public', 'profile_image_folder', filename) )

4 Posts
Login to add your message