2017-07-18 115 views
0

我在收到我上传的特定mp3时遇到了一些麻烦。使用回形针创建mp3上传

我有一个Ruby on Rails应用程序,我使用回形针上传实际的mp3。我正在使用Javascript库(称为jp-player)。我知道mp3文件已经上传,但我没有正式播放它。如果我点击play按钮,则什么都不会发生。

我的模型看起来是这样的:

has_attached_file :mp3 
    validates_attachment :mp3, :content_type => { :content_type => ["audio/mpeg", "audio/mp3"] }, :file_name => { :matches => [/mp3\Z/] } 

我的控制器看起来像

def create 
@cafe = current_user.cafes.build(cafe_params) 

    if @cafe.save 
    redirect_to @cafe 
    else 
    render 'new' 
    end 
end 

def cafe_params 
    params.require(:cafe).permit(:name, :description, :street_address, :state, :editors_note, :website, :image, :mp3) 
end 

我的观点(我有这样的一个部分,我在不同的看法我打电话)

#cafe_content 
    #jquery_jplayer_1.jp-jplayer 
    #jp_container_1.jp-audio 
    .jp-type-single 
     .jp-gui.jp-interface 
     %ul.jp-controls 
      %li 
      %a.jp-play{:href => "javascript:;", :tabindex => "1"}  
      %li 
      %a.jp-pause{:href => "javascript:;", :tabindex => "1"}  
      %li 
      %a.jp-mute{:href => "javascript:;", :tabindex => "1", :title => "mute"}  
      %li 
      %a.jp-unmute{:href => "javascript:;", :tabindex => "1", :title => "unmute"}  
     .jp-progress 
      .jp-seek-bar 
      .jp-play-bar 
     .jp-time-holder 
      .jp-current-time 
     .jp-volume-bar 
      .jp-volume-bar-value 
     .jp-no-solution 
      %span Update Required 
      To play the media you will need to either update your browser to a recent version or update your 
      = succeed "." do 
      %a{:href => "http://get.adobe.com/flashplayer/", :target => "_blank"} Flash plugin 


:javascript 
    $(document).ready(function(){ 
    $("#jquery_jplayer_1").jPlayer({ 
     ready: function() { 
     $(this).jPlayer("setMedia", { 
      mp3: "<%= @cafe.mp3.url %>", 
     }); 
     }, 
     swfPath: "/js", 
     supplied: "mp3" 
    }); 
    }); 

有谁知道是否有什么我失踪,可以得到这个正常运行?

回答

2

可能是你的JP玩家寻求绝对路径,而不是

<%= @cafe.mp3.url %> 

试试这个

<%= URI.join(request.url, @cafe.mp3.url) %>

在你的MP3路径