Displaying a Carrierwave filename in the view

Chris Alley picture Chris Alley · Feb 27, 2011 · Viewed 50.4k times · Source

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

Answer

kikito picture kikito · May 7, 2012

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

<%= @page.form.file.filename %>