im following this sitepoint moviestore tutorial and have everything working fine apart from a a video not loading in an iframe after a user has purchased the movie. I have a csv file with youtube urls in a column for testing the apps payment system (using braintree).
Looking at the source code of the html, the youtube link shows up without the embed part so its finding the info from the db file but its just not inputting the embed into the link. I did actually manage to get a video to work by manually inputting "/embed/" into the youtube link in the CSV.
Im fairly new to rails but if someone could explain why its not working for me id be very grateful.
this is what my movie.rb model looks like:
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
The view contains the 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%>
this is what the controller looks like for movies
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
Thanks in advance!