ruby on rails - Image width and height using carrierwave, not being saved to hstore column, although .persisted? returns true -
ruby 2.1.1p76 (2014-02-24 revision 45161)
rails 4.1.0.rc1
postgres 9.3,
using gems:
gem 'carrierwave'
, gem 'mini_magick'
the issue got unknown reasons uploaded images width , height not being saved database (although without after :store, :set_image_geometry
facebook url , twitter url being saved (using same form, same hstore column))
screencast: http://quick.as/dvvrhnjx
schema.rb - column want store avatar_height , avatar_width
create_table "users", force: true |t| ... t.hstore "settings", default: {}, null: false end
avataruploader.rb
include carrierwave::minimagick after :store, :set_image_geometry ... def set_image_geometry version if self.file.present? && file.exist?(self.file.path) img = minimagick::image.open(self.file.path) self.model.settings['avatar_width'] = img['width'] self.model.settings['avatar_height'] = img['height'] binding.pry self.model.save end end ...
settings_controller.rb
private def user_params params.require(:user).permit(:avatar, :remove_avatar, :avatar_cache, settings: [:facebook_url, :twitter_url, :avatar_width, :avatar_height]) end
everything saving images width , height works intented, im attaching part of console log:
35: def set_image_geometry version 36: if self.file.present? && file.exist?(self.file.path) 37: img = minimagick::image.open(self.file.path) 38: self.model.settings['avatar_width'] = img['width'].to_s 39: self.model.settings['avatar_height'] = img['height'].to_s => 40: binding.pry 41: self.model.save 42: end 43: end [1] pry(#<avataruploader::uploader70137750643660>)> self.model.settings => {"facebook_url"=>"", "twitter_url"=>"", "avatar_width"=>80, "avatar_height"=>58}
i tried both .to_s , without on img['width'], neither works
with no changes made (checked git diff) code started miraculously work supposed to
still no idea caused issue, therefore not marking question answered
Comments
Post a Comment