Difficulty in getting mp3 to work in Paperclip
I am trying to get Paperclip to accept an mp3 file. I was able to get this to work in a Rails 2 app, but am having difficulty in Rails 3. I can get the file to show up in my assets directory, but I continue to get the missing.png listed instead of the appropriate file in the show action.
Here is my model code...
has_attached_file :sermonfile, :url => "/assets/:class/:id/:style/:basename.:extension", :path => ":rails_root/public/assets/:class/:style/:id/:basename.:extension" attr_accessor :sermonfile_file_name attr_accessor :sermonfile_content_type
attr_accessor :sermonfile_file_size
attr_accessor :sermonfile_updated_at
Here is the form view...
<%= form_for @sermon, :html => {:multipart => true} do |f| %> <% if @sermon.errors.any? %>
<%= pluralize(@sermon.errors.count, "error") %> prohibited this sermon from being saved:
<ul>
<% @sermon.errors.full_messages.each do
|msg| %>
<%= f.label :title %>
<%= f.text_field :title %> <%= f.label :permalink %>
<%= 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 :passage %>
<%= f.text_field :passage %> <%= f.label :notes %>
<%= f.text_area :notes, :class => "mceEditor" %> <%= f.file_field :sermonfile %> <%= f.submit %> <% end %>
This is what I am using to render the file in the show view...
<%= link_to @sermon.sermonfile.url %>
Any assistance is greatly appreciated!
Your :url
& :path
have their :id
& :style
mixed up. They should be the same: :id/:style
has_attached_file :sermonfile,
:url => "/assets/:class/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/:class/:id/:style/:basename.:extension"
链接地址: http://www.djcxy.com/p/35970.html
上一篇: 行为上的怪异行为
下一篇: 难以让MP3在Paperclip中工作