Skip to content

Instantly share code, notes, and snippets.

@chebyte
Created June 28, 2011 13:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chebyte/1051122 to your computer and use it in GitHub Desktop.
Save chebyte/1051122 to your computer and use it in GitHub Desktop.
upload video with youtube_it from web
#application_controller.rb
class ApplicationController < ActionController::Base
helper_method :yt_client
private
def yt_client
@yt_client ||= YouTubeIt::Client.new(:username => user, :password => password, :dev_key => dev_key)
#you can use the auth method that you want.
end
end
#videos_controller.rb
def new
@video = Video.new
respond_to do |format|
format.html { render "/videos/_step1" }
end
end
def upload
@upload_info = yt_client.upload_token(params[:video], videos_url)
respond_to do |format|
format.html { render "/videos/_step2" }
end
end
#views
#_step1.html.erb
<%= form_for @video, :url => upload_videos_path do |f| %>
<li>
Step 1 to add a new video.
</li>
<li>
<label>Title of piece</label>
<br />
<%= f.text_field :title %>
</li>
<li>
<label>Description</label>
<br />
<%= f.text_area(:description, :cols => 43, :rows => 10) %>
</li>
<li>
<%= f.submit %>
</li>
<% end %>
#_step2.html.erb
<li>
Step 2 to post a new video.
</li>
<%= form_tag @upload_info[:url], :multipart => true do %>
<%= hidden_field_tag :token, @upload_info[:token] %>
<%= label_tag :file %>
<%= file_field_tag :file %>
<%= submit_tag "Upload video" %>
<% end %>
#routes
resources :videos do
new do
post :upload
end
end
@divyang1989
Copy link

How Can I merge this two step in single step?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment