Hi ,
i want uplaod videos using youtube model pluign and youtube api. i
follow all instructions . But i am getting below error .
###########################################################################
Error:
can’t convert nil into String
app/controllers/videos_controller.rb:42:in `create’
Request
Parameters:
{“commit”=>“Create”,
“authenticity_token”=>“bb4gNcdtGNNo4fsCJt/vZxEYP+7B7L3NtTD2OmmWsJU=”,
“utf8”=>"\342\234\223",
“vid”=>{“category”=>“Film”,
“auth_sub”=>“1/-jwDoI3pYKaS4JUdoTXjNjWezgjDQ4mStDXZy1nk8ag”,
“title”=>“sdgsdgds”,
“token”=>“1/-jwDoI3pYKaS4JUdoTXjNjWezgjDQ4mStDXZy1nk8ag”,
“description”=>"",
“file”=>#<ActionDispatch::Http::UploadedFile:0x6712638
@content_type=“video/x-msvideo”,
@headers=“Content-Disposition: form-data; name=“vid[file]”;
filename=“butterfinger-surprise.avi”\r\nContent-Type:
video/x-msvideo\r\n”,
@original_filename=“butterfinger-surprise.avi”,
@tempfile=#<File:C:/DOCUME~1/Anu/LOCALS~1/Temp/RackMultipart20110522-5484-1s9c9tt-0>>,
“keywords”=>""}}
##########################################################################
Here my code:
In controller:
def authorise
client = GData::Client::DocList.new
if params[:token]
client.authsub_token = params[:token] # extract the single-use token
from the URL query params
session[:token] = client.auth_handler.upgrade()
client.authsub_token = session[:token] if session[:token]
end
redirect_to videos_path
end
def new
@categories ||= Vid.video_categories
@video = Vid.new(:token => session[:token])
end
def create
@video = Vid.new(params[:vid])
if !@video.save
render :action => :new
end
end
In views:
Untitled Document<%= form_for(@video, :url => {:action => "create" ,:controller
=>“videos”}, :html => {:multipart => true}) do |f| %>
<% if @video.errors.any? %>
<%= pluralize(@video.errors.count, "error") %> prohibited this user from being saved:
-
<% @video.errors.full_messages.each do |msg| %>
- <%= msg %> <% end %>
<%= f.hidden_field :auth_sub, :value => session[:token] %>
<%= f.text_field :token , :value => session[:token] %>
<br/>
<%= f.label :title %>
<%= f.text_field :title %>
<%= f.label :description %> <%= f.text_area :description, :rows => 6 %>
<%= f.label :category %>
<%= f.select :category, @categories %>
<%= f.label :keywords %>
<%= f.text_field :keywords %>
<%= f.label :file %>
<%= f.file_field :file %>
<%= f.submit 'Create' %>
<% end %>
In model:
class Vid < YouTubeModel::Base #inherits from ActiveResource::Base
self.default_youtube_options= {:itemPerPage => 10}
schema do
attribute :title, :string
attribute :description, :string
attribute :keywords, :string
attribute :category, :string
attribute :file, :string
attribute :token, :string
end
validates_presence_of :title
validates_presence_of :token #needed on remote crud operation
validates_presence_of :file, :if => Proc.new{|vid| vid.new? }
end
Vid.top_rated(:startIndex => 10, :itemPerPage => 30)
Let me know any one about this error .
Thanks in advance.