Class: HeadshotController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- HeadshotController
- Includes:
- HeadshotSupport
- Defined in:
- lib/app/controllers/headshot_controller.rb
Instance Method Summary collapse
Methods included from HeadshotSupport
#headshot_file_path, #headshot_file_timestamp, #headshot_image_url, #headshot_save_image
Instance Method Details
#capture ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/app/controllers/headshot_controller.rb', line 3 def capture file_path = '' begin file_path = method(:headshot_custom_file_path).call rescue file_path = headshot_file_path end # Pre save hook. begin method(:headshot_pre_save).call(file_path) rescue # No pre save hook. end # Method for saving the JPEG file. begin method(:headshot_custom_save_image).call(file_path, request.raw_post) # Only catch the error if method is undefined. rescue NameError => e saving_result = headshot_save_image(file_path, request.raw_post) unless saving_result render :json => { :status => 'Error', :message => 'Saving of headshot failed.' } return end end # Post save hook. begin method(:headshot_post_save).call(file_path) rescue @headshot_photo = HeadshotPhoto.create( :image_file_name => File.basename(file_path), :image_content_type => 'image/jpeg', :image_updated_at => Time.now ) end headshot_url = "" begin headshot_url = method(:headshot_custom_image_url).call(File.basename(file_path)) rescue headshot_url = "#{headshot_image_url(File.basename(file_path))}" end render :json => { :status => 'Success', :message => 'Headshot saved.', :url => headshot_url } end |