Трудности с получением mp3 для работы в Paperclip - PullRequest
2 голосов
/ 03 апреля 2011

Я пытаюсь заставить Paperclip принять файл mp3.Мне удалось заставить это работать в приложении на Rails 2, но у меня возникли трудности с Rails 3. Я могу заставить файл отображаться в моем каталоге ресурсов, но я продолжаю отображать отсутствующий файл.png вместо соответствующего файлав действии show.

Вот мой код модели ...

has_attached_file: sermonfile,: url => "/ assets /: class /: id /: style /:basename.:extension ",: path =>": rails_root / public / assets /: класс /: стиль /: id /: basename.: расширение "attr_accessor: sermonfile_file_name attr_accessor: sermonfile_content_type
attr_accessor: sermonfile_file_size_orize * 1007sermonfile_updated_at

Вот представление формы ...

<% = form_for @sermon,: html => {: multipart => true} do | f |%> <% if @ sermon.errors.any?%>

<% = множественное число (@ sermon.errors.count, "error")%> запретило сохранение этой проповеди:

  <ul>
  <% @sermon.errors.full_messages.each do

| msg |%>

<% = msg%> <% end%> <% end%>

<% = f.label: title%><% = f.text_field: title%> <% = f.label: постоянная ссылка%><% = f.text_field: permalink%> <% = f.label: speaker%><% = f.text_field: speaker%> <% = f.label: date%><% = f.date_select: date%> <% = f.label: series%><% = f.text_field: series%> <% = f.label: book%><% = f.text_field: book%> <% = f.label: проход%><% = f.text_field: проход%> <% = f.label: notes%><% = f.text_area: notes,: class => "mceEditor"%> <% = f.file_field: sermonfile%> <% = f.submit%> <% end%>

Это то, что я использую для рендеринга файла в режиме просмотра ...

<% = link_to @ sermon.sermonfile.url%>

Любая помощьс благодарностью!

1 Ответ

1 голос
/ 03 апреля 2011

У ваших :url & :path есть :id & :style. Они должны быть одинаковыми: :id/:style

has_attached_file :sermonfile, 
  :url => "/assets/:class/:id/:style/:basename.:extension", 
  :path => ":rails_root/public/assets/:class/:id/:style/:basename.:extension" 
...