Created
June 28, 2011 13:24
-
-
Save chebyte/1051122 to your computer and use it in GitHub Desktop.
upload video with youtube_it from web
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How Can I merge this two step in single step?