Paperclip attachment file size

前端 未结 4 763
难免孤独
难免孤独 2021-01-18 07:52

How do I fetch the file size of each style of a paperclip attachment?

@user.attachment_file_size doesn\'t seem to work

@user.attachment(         


        
4条回答
  •  盖世英雄少女心
    2021-01-18 08:27

    You can get a string like "WIDTHxHEIGHT" inside styles hash, for the giving object's style, using Paperclip::Style#geometry:

    string = @user.attachment.styles[:size].geometry
    

    Than you can split the string to have either height or width:

    width = string.split("x")[0]
    
    height = string.split("x")[1]
    

提交回复
热议问题