Displaying a Carrierwave filename in the view

前端 未结 10 1114
暖寄归人
暖寄归人 2020-12-13 23:29

I am trying to display the filename of a Carrierwave attachment in a Rails erb template. The following does not work:

<%= @page.form.filename %>
         


        
10条回答
  •  温柔的废话
    2020-12-13 23:49

    The documentation you're looking at is the sanitized file, it's what it uses for actually storing a file. The part you're looking for is FormUploader, which is an Uploader, and part of http://rubydoc.info/gems/carrierwave/0.5.2/CarrierWave/Uploader

    If you want to get the file name, you could either read it from the database column directly, or use File.basename(@page.form.path) to extract it easily.

提交回复
热议问题