简体   繁体   中英

Rails3 model gets stuck when using paperclip has_attached_file

When I try to save an unvalid model object I don'tget an error message but my app gets stuck, I expect the test to fail not to get stuck. (when using with valid attributes, ie specifying an image file everything works as expected an the object is valid.)

I found out that it's becasue of paperclip when using has_attached_file :image any ideas why it happens?

models/user_image.rb

 has_attached_file :image  
 :image_content_type, :presence => true
 validate :valid_res        

 validates_attachment_content_type
 :image,    :content_type =>
 ['image/jpeg','image/jpg','[image/jpeg]',
 '[image/png]', 'image/png'] ...

user_image_spec.rb

describe UserImage do

before(:each) do
  @user_image = UserImage.new(
  :uid => "1234abca"
  )
end

it "is valid with valid attributes" do
  @user_image.should be_valid
end

Update: I was using the paperclip plugin, so I removed it and installed the gem. still getting the same result, am i suppose to do something after installing the gem?

要验证PaperClip图像,只需添加:

validates :image, :attachment_presence => true

I am not sure what does this line means:

:image_content_type, :presence => true

I think this one causes your troubles

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM