exifr gemを使用してペーパークリップでアップロードしたjpeg画像からexifデータを読み取ろうとしており、焦点距離などを属性に保存しようとしていますが、それができないようです。私はレールの初心者であり、誰かが助けてくれるなら最も感謝するでしょう。
私のphoto.rbモデル:
class Photo < ActiveRecord::Base
attr_accessible :date, :exif, :name, :photo
has_attached_file :photo, :styles => { :small => "200x200#" , :medium => "1280x720#" },
:url => "/assets/photos/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/photos/:id/:style/:basename.:extension"
after_photo_post_process :load_exif
validates_attachment_presence :photo
validates_attachment_content_type :photo, :content_type => ['image/jpeg']
def load_exif
exif = EXIFR::JPEG.new(photo.queued_for_write[:original])
return if exif.nil? or not exif.exif?
self.exposure = exif.exposure_time.to_s
self.f_stop = exif.f_number.to_f.to_s
self.focal_length = exif.focal_length.to_f.round.to_s
self.iso = exif.iso_speed_ratings
self.date = exif.date_time.to_date
rescue
false
end
end
私のフォーム(SimpleFormを使用):
<%= simple_form_for @photo, :html => {:multipart => true} do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :name %>
<%= f.file_field :photo, :label => 'Attach photo' %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
私が表示しようとしているフィールドを持つshow.html.erb:
<p>
<b>Name:</b>
<%= @photo.name %>
</p>
<p>
<b>Date:</b>
<%= @photo.date %>
</p>
<p>
<b>Exposure:</b>
<%= @photo.exposure %>
</p>
私はおそらく愚かな何かを見逃しているので、そうであればお詫びします。