Rails and Paperclip, default_url not working

北城以北 提交于 2019-11-30 06:04:05

问题


I'm using paperclip for uploading profile pictures. When someone does not upload an image I want a default image to be assigned to the user instead.

I'm using this line of code:

has_attached_file :avatar, 
  styles: { medium: "300x300>", thumb: "100x100>" },
  default_url: "assets/images/:style/male.jpg"

But my browser inspector gives me this error:

http://localhost:3000/assets/images/original/male.jpg 404 (Not Found)

I've tried writing:

default_url: "assets/images/:style/male.jpg"
default_url: "images/:style/male.jpg"
default_url: ":style/male.jpg"
default_url: "male.jpg"
default_url: "assets/images/male.jpg"

The image lies in the following places:

/assets/images/male.jpg 
/assets/images/medium/male.jpg 
/assets/images/thumb/male.jpg 
/assets/images/original/male.jpg 

回答1:


Ommit the /images/ instead do this /assets/male.jpg or /assets/original/male.jpg

Hope that help you out.



来源:https://stackoverflow.com/questions/38665593/rails-and-paperclip-default-url-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!