attribute not being saved

12 views
Skip to first unread message

Bob Sleys

unread,
Sep 27, 2011, 2:04:25 PM9/27/11
to hobo...@googlegroups.com
I have an attachment via paperclip and the paperclip with hobo extension.  The image gets uploaded fine etc but I'm trying to save the image dimensions and the middle point of the image (the mid point is used/changed in other parts of the app it just set to the middle of the image to initialize it).  I have a method save_image_dimensions that is part of the model. It sets 4 attributes but only 3 of the 4 are getting saved to the database.  If I debug the code and inspect the self object it has all the attributes set properly but if I then check the log file the dwg_origin_y value is nil.  Below is the code.  This is very baffling to me since 3 of the 4 values get saved just fine.  I've highlighted the attribute in the code below that doesn't get saved.

require "pdf_converter.rb"
class Floor < ActiveRecord::Base

  hobo_model # Don't put anything above this
  include ActiveModel::Dirty

  fields do
    name :string, :required
    layout_width :integer
    layout_height :integer
    drawing_scale :float
    dwg_origin_x :float
    dwg_origin_y :float
    timestamps
  end

  set_default_order "name DESC"

  has_attached_file :layout, :styles => {:jpg => {:format=>:jpg, :rotate=>"270"}}, :processors => [:pdf_converter]
  has_attached_file :csv
  validates_attachment_content_type :csv, :content_type =>
          ['text/csv', 'text/comma-separated-values', 'text/csv', 'application/csv',
           'application/excel', 'application/vnd.ms-excel', 'application/vnd.msexcel', 'text/anytext', 'text/plain', 'application/octet-stream']

  belongs_to :building

  has_many :spaces, :dependent => :destroy

  children :spaces

  after_layout_post_process :save_image_dimensions

  after_save :import_spaces

  def save_image_dimensions
    geo = Paperclip::Geometry.from_file(layout.queued_for_write[:jpg])

    self.layout_width = geo.width
    self.dwg_origin_x = geo.width/2

    self.layout_height = geo.height
    self.dwg_origin_y  = geo.height/2

    true
  end

 ....

end

Any hints as to what might be going on here would be appreciated.

Bob

kevinpfromnm

unread,
Sep 27, 2011, 2:21:03 PM9/27/11
to hobo...@googlegroups.com
I don't see anything there, but might suggest restarting server/double checking migrations are up to date.

Bob Sleys

unread,
Sep 27, 2011, 2:41:38 PM9/27/11
to hobo...@googlegroups.com
Thanks for looking but ya done all that this has been going on for a long time but I've been avoiding it and working on other things.  It just makes no sense to me since the other attributes are updated fine and I can see the value as part of the attribute list when debugging.  It's not a show stopper issue just one that make me pull my hair out trying to figure out what's wrong.
Reply all
Reply to author
Forward
0 new messages