Setting Custom error message with CarrierWave

后端 未结 4 1040
迷失自我
迷失自我 2020-12-31 09:26

I have an Image uploading application running on carrierwave which restrict user from uploading image only of desired extensions \'jpg,jpeg,png\' I have put in place the v

相关标签:
4条回答
  • 2020-12-31 10:08

    If someone ends up here in 2016+ and wonders why correct answers found on this page or anywhere else in the web do not work, it could be because of this. At least it was in my case:

    Rename extension_white_list ~> extension_whitelist

    Easy thing to miss when just copying solutions.

    https://github.com/carrierwaveuploader/carrierwave/commit/06003a5044190f93d07d958b6ca9fd6f6f8fbdb2

    0 讨论(0)
  • 2020-12-31 10:09

    Add this to your .yml translation file:

    en:
      errors:
        messages:
          extension_white_list_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
          content_type_whitelist_error: "You are not allowed to upload %{content_type} files, allowed types: %{allowed_types}"
    

    Source:

    https://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/locale/en.yml

    0 讨论(0)
  • 2020-12-31 10:17

    for some reason my ActiveModel did not include the validation module from carrierwave upon calling mount_uploader. I had to do include CarrierWave::Validations::ActiveModel in my model to get the integrity validator.

    0 讨论(0)
  • 2020-12-31 10:20

    Actually it is:

    en:
      errors:
        messages:
          extension_white_list_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
    

    Source:

    https://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/locale/en.yml

    0 讨论(0)
提交回复
热议问题