ruby on rails 4 - default_url method of carrierwave doesn't work with me -
I have a problem with carrier congestion default_url method because it does not work. My code looks like this
class ImageFileUploader & lt; CarrierWave :: Uploader :: Base included CarrierWave :: MiniMagick storage: file def store_dir "upload / # {model.class.to_s.underscore} / # {mounted_as} / # {model.id}" end version: perform small process : Resize_to_fill = & gt; [75, 75] and version: Thumb processing: resize_to_fill = & gt; [120, 120] and version: The medium process is: resize_to_fill = & gt; [639, 426] and def extension_white_list% w (jpg jpeg gif png) and version: thumb_default_avatar process: resize_to_fill = & gt; [120, 120] End DEF DEFAULT_URL ActionController :: Base.helpers.asset_path ("Fallback /" + [thumb_default_avatar.jpg, "default_avatar.jpg"]. Compact.join ('_')) End End
< / Pre>And I have this model that gives me the default_quirite image
class agent & lt; I need to set my avatar with I ActiveRecord :: Base mount_uploader:. Avatar, ImageFileUploader End
In addition, thanks to the default_avatar.jpg image in the "Public" folder in a "fallback" folder created in advance
Thanks in advance.
default_url
To work on the method, you must take the place Typical default images ie small_default_avatar.jpg
, thumb_default_jpg
and medium_default_jpg
in public / return
( Public ). Therefore, when you do not upload an image for a record, instead of showing a broken image icon default_url
will display carrierw
image
According to the share for update
code ImageFileUploader
, you 4 are making any image uploading versions i.e. : small
, : thumb
, : middle
and : thumb_default_avatar
. Therefore, you should rationalize the version specific default images in the public / fallback
folder. Therefore, for example, if you were trying to render the image with the version : small
in the image view of your agent and the image was not uploaded, the agent's composition is broken Instead of showing the default image for the version image: small
ie, small_default_avatar.jpg
will be raised to display.
Update 2
The default URL is not saved in the database In runtime, carrier service
checks whether an agent is a Whether the image was uploaded or not. If the image was uploaded then it displays the image from the stored directory and if the image is not uploaded, it displays the default image directly, therefore, no, you are not going to store the default URL in the database.
Comments
Post a Comment