2012-11-21 23 views
0

我試圖用exifr gem讀取圖片上傳的緯度/經度。經緯度不在紅寶石的EXIFR寶石中

在模型:

attr_accessible :image, :post_process_photo, :width, :height, :model, :datetime, :latitude, :longitude 

belongs_to :user 

    has_attached_file :image, styles: { medium: "300x300#", thumb: "50x50#", large:"500x500#" } 

    after_post_process :post_process_photo 

    def post_process_photo 
     imgfile = EXIFR::JPEG.new(image.queued_for_write[:original].path) 
     return unless imgfile 

     self.width   = imgfile.width    
     self.height  = imgfile.height    
     self.model   = imgfile.model    
     self.datetime  = imgfile.date_time  
     self.latitude  = imgfile.gps.latitude 
     self.longitude  = imgfile.gps.longitude 

     end 

在視圖...寬度/高度東西正在工作,但緯度/經度不是:

<%= @pic.width %> #this works! 

<%= @pic.height %> #this works! 

<%= @pic.latitude %> #this doesn't! 

<%= @pic.longitude %> #this doesn't! 

...是奇,因爲它的標記完全按照gem docs中的說明進行。

已經將相應的遷移添加到了數據庫中,這在數據庫中應該顯示出來。

視圖呈現undefined method latitude'`

任何幫助,非常感謝!

回答

0

我想你想imgfile.gps_latitude和imgfile.gps_longitude - 下劃線而不是點