开发者

Rails 3 gdata site wide youtube client

开发者 https://www.devze.com 2023-03-14 01:49 出处:网络
i want to uses youtube\'s api within rails. I need a client which is able to access youtubes api application wide.

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号