kylejginavan / youtube_it

An object-oriented Ruby wrapper for the YouTube GData API
http://groups.google.com/group/ruby-youtube-library
595 stars 223 forks source link

Undefined method join for nil:nilClass #148

Closed reydelleon closed 11 years ago

reydelleon commented 11 years ago

Hello. I'm using youtube_it gem(a really gem indeed) to build a website that is heavily dependent on youtube videos. I've set up the whole thing, and I was able to upload a video in a test I carried out. After some changes in my website, I tried to upload another video, but this time a got the error I put below: "undefined method 'join' for nil:NilClass"

This is my upload method(the one firing the error):

def upload begin @video = Video.new @video.title = params[:video][:title] @video.provider = 'youtube' @video.band = Band.find(Integer(params[:video][:band])) if !params[:video][:band].to_s.empty? @video.genre = Genre.find(Integer(params[:video][:genre])) if !params[:video][:genre].to_s.empty? raw_tags = params[:video][:keywords] tags = raw_tags.split(',') @video.keywords = tags @video.description = params[:video][:description] @video.save! session[:new_video] = @video.id upload_opts = {:title => @video.title, :tags => @video.keywords, :category => "Music", :description => @video.description} puts upload_opts.inspect @upload_info = simple_user_yt_client.upload_token(upload_opts, save_video_new_video_url) #####THIS IS THE PROBLEMATIC LINE###### rescue Exception => exep puts "**THIS IS THE PROBLEM: " + exep.message + "*****" Video.delete_incomplete_videos flash[:notice] = exep.message respond_to do |format| format.html { redirect_to :action => 'new' } end end end

And this is the simple_user_yt_client method, that returns the client(It is returning the client as expected, the problem seems to be in the uploadtoken method). All the necessary configurations have been set:

private def simple_user_yt_client @yt_client ||= YouTubeIt::Client.new(:username => YouTubeITConfig.username, :password => YouTubeITConfig.password, :dev_key => YouTubeITConfig.dev_key, :client_id => "Plaker") end

My video model is this(at least the relevant part):

class Video < ActiveRecord::Base acts_as_commentable

attr_accessible :title, :description, :keywords attr_accessor :comment

belongs_to :band belongs_to :genre

has_many :video_plaks, :dependent => :destroy has_many :video_fucks, :dependent => :destroy has_many :play_lists_videos, :dependent => :destroy#TODO Define a better behaviour has_many :play_lists, :through => :play_lists_videos

validates :video_code, :uniqueness => true

validates :title, :genre, :band, :keywords, :description, :presence => true

scope :completes, where(:is_complete => true) scope :incompletes, where(:is_complete => false) end

And this is the video table structure:

create_table "videos", :force => true do |t| t.string "title", :null => false t.text "description" t.datetime "created_at" t.datetime "updated_at" t.string "keywords" t.integer "views", :default => 0 t.integer "downloads", :default => 0 t.integer "band_id" t.string "provider", :default => "Plaker" t.integer "genre_id", :null => false t.string "video_code" t.boolean "is_complete", :default => false end

Any help will be appreciated.

reydelleon commented 11 years ago

Solved! I installed the better_errors gem, and found out the problem. I was passing :tags => @video.keywords in the options of upload_token. I changed to :keywords and it worked fine. Thanks for this gem, it helped me a lot.