Displaying a Carrierwave filename in the view

前端 未结 10 1137
暖寄归人
暖寄归人 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-14 00:02

    In your model's associated uploader class, define a filename method.

    def filename
      File.basename(path)
    end
    

    You can then call

    model_instance.file.filename
    

    Works as of CarrierWave 1.1.0. This is a succinct restatement/amalgamation of kikito and Chris Alley's responses above.

提交回复
热议问题