我想让Paperclip接受一个mp3文件。我能够在Rails 2应用程序中使用它,但在Rails 3中遇到困难。我可以将文件显示在我的资产目录中,但我继续将missing.png列出而不是相应的文件在节目动作中。
这是我的型号代码......
has_attached_file:sermonfile, :url => “/assets/:class/:id/:style/:basename.:extension” :path => “:RAILS_ROOT /公/资产/:类/:款式/:ID /:基本名称:扩展名” attr_accessor:sermonfile_file_name attr_accessor :sermonfile_content_type
attr_accessor:sermonfile_file_size
attr_accessor:sermonfile_updated_at
这是表格视图......
<%= form_for @sermon,:html => {:multipart => true} do | f | %GT; <%if @ sermon.errors.any? %GT;
<%= pluralize(@ sermon.errors.count, “错误”)%>禁止这篇讲道 从被保存:
<ul> <% @sermon.errors.full_messages.each do
| MSG | %GT;
&lt;%= msg%&gt; &lt;%end%&gt; &lt;%end%&gt;
&lt;%= f.label:title%&gt;
&lt;%= f.text_field:title%&gt; &lt;%= f.label:permalink%&gt;
&lt;%= f.text_field:永久链接%&gt; &lt;%= f.label:speaker%&gt;
&lt;%= f.text_field:speaker%&gt; &lt;%= f.label:date%&gt;
&lt;%= f.date_select:date%&gt; &lt;%= f.label:series%&gt;
&lt;%= f.text_field:series%&gt; &lt;%= f.label:book%&gt;
&lt;%= f.text_field:book%&gt; &lt;%= f.label:pass%&gt;
&lt;%= f.text_field:passage%&gt; &lt;%= f.label:notes%&gt;
&lt;%= f.text_area:notes,:class =&gt; “mceEditor”%&gt; &lt;%= f.file_field :sermonfile%&gt; &lt;%= f.submit%&gt; &lt;%end%&gt;
这就是我用来在show view中渲染文件...
&lt;%= link_to @ sermon.sermonfile.url%&gt;
非常感谢任何帮助!
答案 0 :(得分:1)
您的:url
&amp; :path
有:id
&amp; :style
混淆了。它们应该是相同的::id/:style
has_attached_file :sermonfile,
:url => "/assets/:class/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/:class/:id/:style/:basename.:extension"