how to use youtube-g ruby gem? -


new rails , trying youtube-g work... having difficult time passing users search form_tag controller.. example:

  1. user lands on page, enters - tiger videos - in text_field_tag
  2. controller takes - tiger videos - , searches
  3. user lands on page displaying results...

  4. user lands on page, enters query

index.html.erb

<%= form_tag(youtube_path) %>      <%= label_tag(:q, "search for:") %>      <%= text_field_tag(:wth) %>      <%= submit_tag("search") %>     <% end %> 

--

  1. controller takes query , searches

youtubecontroller.rb

class youtubecontroller < applicationcontroller def search   require 'youtube_g'   client = youtubeg::client.new client.videos_by(:query => params[:wth]) end end 

--

my routes file:

actioncontroller::routing::routes.draw |map| map.search “search”, :controller => “youtube” 

i havn´t got step 3 yet..

what want page text box , submit button, , when user enters text , submits, brought new page renders 10 youtube results. appreciated!!!

http://youtube-g.rubyforge.org/

search.html.erb

 <%= form_tag(:action => "search") %>        <%= label_tag(:q, "search for:") %>        <%= text_field_tag(:wth) %>        <%= submit_tag("search") %>    <% end %> 

youtubecontroller

require 'youtube_g' class youtubecontroller < applicationcontroller   def index            end    def search       if request.post?      client = youtubeg::client.new      @youtube = client.videos_by(:query => params[:wth],:per_page => 10)               render :action => :index     end    end end 

index.html.erb

<% @youtube.videos.each |video| %>    <%= video.title %> <% end %> 

routes.rb

 map.resources :youtube, :collection => { :search => :get } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -