1

my model uses carrierwave

class Image < ActiveRecord::Base

  belongs_to :imageable, :polymorphic => true
  mount_uploader :image, PropertyUploader

end

And I can't update manually field that carrierwave does.

Here is a console log

 image = Image.where(:id => '12345').first
  Image Load (0.7ms)  SELECT "images".* FROM "images" WHERE "images"."id" = 12345 ORDER BY "images"."id" ASC LIMIT 1
 => #<Image id: 12345, image: "3d-Fractal-Art.jpg", imageable_id: 10, imageable_type: "Category", created_at: "2014-02-04 08:17:00", updated_at: "2014-02-04 08:41:38"> 

 image.image = ''
 => "" 
 image.save
   (0.3ms)  BEGIN
  Image Load (0.4ms)  SELECT "images".* FROM "images" WHERE "images"."id" = $1 LIMIT 1  [["id", 12345]]
  SQL (0.9ms)  UPDATE "images" SET "image" = $1, "updated_at" = $2 WHERE "images"."id" = 12345  [["image", "3d-Fractal-Art.jpg"], ["updated_at", Tue, 04 Feb 2014 08:53:08 UTC +00:00]]
   (272.8ms)  COMMIT
 => true 

I can update 'id', delete record but can't get access to field 'image'. SOLVED image.update(:remove_image => true) helps me but I still don't know how to set something else then empty string

Sergei Tsibulchenko
  • 297
  • 1
  • 5
  • 17

2 Answers2

0

You need to mention attr_accessible attribute in the model.

TLama
  • 75,147
  • 17
  • 214
  • 392
VDN
  • 498
  • 3
  • 15
-1

Try this

image.image_url

Check the below link 

http://railscasts.com/episodes/253-carrierwave-file-uploads

David
  • 15,894
  • 22
  • 55
  • 66
VDN
  • 498
  • 3
  • 15