Ruby中的初学者!
我正在尝试在ruby上创建一个Soundcloud克隆。
当我尝试上传音频文件时,我收到错误:
1错误禁止保存此歌曲:
音频的内容不是报告的内容
controller:song.rb
class Song < ActiveRecord::Base
belongs_to :user
has_attached_file :audio,
:url => "/assets/:class/:id/:attachment/:basename.:extension",
:path => ":rails_root/public/assets/:class/:id/:attachment/:basename.:extension"
validates_attachment :audio,
:content_type => { :content_type => ["audio/mpeg", "audio/mp3"] },
:file_name => { :matches => [/mp3\Z/] }
_form.html.erb
<%= form_for(@song) do |f| %>
<% if @song.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@song.errors.count, "error") %> prohibited this song from being saved:</h2>
<ul>
<% @song.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :audio %><br>
<%= f.file_field :audio%>
</div>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_field :description %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
show.html.erb
<p id="notice"><%= notice %></p>
<p>
<strong>Audio:</strong>
<%= @song.audio.url %>
</p>
<p>
<strong>Title:</strong>
<%= @song.title %>
</p>
<%= link_to 'Edit', edit_song_path(@song) %> |
<%= link_to 'Back', songs_path %>
答案 0 :(得分:0)
根据我对这个问题的经验,mp3元数据中的图像数据(即专辑封面)是关键因素。图像数据会触发内容类型欺骗机制,并且记录将无法通过验证。为了删除图像元数据,我打开了带有Audacity的mp3,并将其导出到一个新文件中,该文件将不包含图像元数据,因为Audacity似乎并未自动包含该文件。