【发布时间】:2014-11-04 03:06:09
【问题描述】:
我正在关注此 sitepoint moviestore tutorial,除了在用户购买电影后视频未加载到 iframe 中之外,一切正常。我有一个 csv 文件,其中有一列包含 youtube 网址,用于测试应用支付系统(使用 Braintree)。
查看 html 的源代码,youtube 链接显示没有嵌入部分,因此它从 db 文件中查找信息,但它只是没有将嵌入输入到链接中。实际上,我确实设法通过在 CSV 中的 youtube 链接中手动输入“/embed/”来制作视频。
我对 Rails 很陌生,但如果有人能解释为什么它对我不起作用,我将不胜感激。
这就是我的 movie.rb 模型的样子:
class Movie < ActiveRecord::Base
has_many :purchases
has_many :buyers, through: :purchases
before_save :embed_video_url
def poster
"http://ia.media-imdb.com/images/M/#{poster_url}"
end
def imdb
"http://www.imdb.com/title/#{imdb_id}/"
end
def embed_video_url
self.video_url = "//www.youtube.com/embed/#{video_url.split('v=')[1].split('&list')[0]}"
end
def cart_action(current_user_id)
if $redis.sismember "cart#{current_user_id}", id
"Remove from"
else
"Add to"
end
end
end
视图包含 iframe
<%if signed_in?%>
<%if current_user.purchase? @movie %>
<div class="flex-video">
<iframe title="YouTube video player" width="100%" height="" src="<%= @movie.video_url %>" frameborder="0" allowfullscreen></iframe>
</div>
<%else%>
<%=link_to "", class: "button", data: {target: @cart_action, addUrl: add_to_cart_path(@movie), removeUrl: remove_from_cart_path(@movie)} do%>
<i class="fi-shopping-cart"></i>
<span><%=@cart_action%></span> Cart
<%end%>
<%end%>
这就是电影控制器的样子
class MoviesController < ApplicationController
def index
@movies = Movie.all
end
def show
@movie = Movie.find(params[:id])
@cart_action = @movie.cart_action current_user.try :id
end
end
提前致谢!
【问题讨论】:
标签: javascript ruby-on-rails ruby iframe youtube