Displaying a Carrierwave filename in the view

前端 未结 10 1134
暖寄归人
暖寄归人 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:53

    This is my solution:

      before_save :update_file_attributes
    
    
      def update_file_attributes
        if file.present? && file_changed? 
          self.content_type = file.file.content_type
          self.file_size = file.file.size
          self.file_name = read_attribute(:file)
        end
      end
    

提交回复
热议问题