Rails 3 gdata site wide youtube client
i want to uses youtube's api within rails.
I need a client which is able to access youtubes api application wide. therefore i wrote the following application controller
require 'gdata'
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :auth
def auth
@client = GData::Client::YouTube.new
@client.clientlogin('usermail', 'password')
@client
end
end
i am able to use the client now in my controllers which extend ApplicationController. thats working fine. but it开发者_如何学JAVAs pretty slow.
is there a way to do the authentication once and using it application wide instead of suing the before_filter which is getting called every single time before i call a method?
best,
philip
This is a web page. Webpages are state-less. Thus you cannot preserve any state. Thus you cannot preserve your login across requests. Thus you have to auth every request.
An alternative would be to only run the before filter on certain controller actions. Right now it runs on every action, which my be not necessary.
Try:
before_filter :auth, :only=> my_action_name
(P.S. That might be the wrong syntax -- I'm confused 'cause rails changes so much -- just look it up)
精彩评论