Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying a Carrierwave filename in the view

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

<%= @page.form.filename %> 

This seems in line with the documentation. Is some additional step needed?

My page model looks like this:

class Page < ActiveRecord::Base    mount_uploader :form, FormUploader  end 

The form uploader looks like this:

class FormUploader < CarrierWave::Uploader::Base    storage :file    def store_dir     "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"   end    def extension_white_list     %w(pdf)   end  end 
like image 901
Chris Alley Avatar asked Feb 27 '11 11:02

Chris Alley


1 Answers

I have been able to get the filename via the file internal parameter:

<%= @page.form.file.filename %> 
like image 132
kikito Avatar answered Sep 28 '22 04:09

kikito