2012-01-18 2 views
1

그래서 내가 여기에 몇 가지 코드를 나는 레일 스위퍼에 대한 수정해야했다 :레일 : 스위퍼에서 컨트롤러 변수에 액세스

class UserTrackingSweeper < ActionController::Caching::Sweeper 
    observe User 

    def after_update(user) 
    return if user.nil? || user.created_at.nil? #fix weird bug complaining about to_date on nil class 
    return if user.created_at.to_date < Date.today || user.email.blank? 

    user.send_welcome_email if user.email_was.blank? 
    end 

    #use sweeper as a way to ingest metadata from the user access to the site automatically 
    def after_create(user) 
    begin 
     if !cookies[:user_tracking_meta].nil? 
     full_traffic_source = cookies[:user_tracking_meta] 
     else 
     if !session.empty? && !session[:session_id].blank? 
      user_tracking_meta = Rails.cache.read("user_meta_data#{session[:session_id]}") 
      full_traffic_source = CGI::unescape(user_tracking_meta[:traffic_source]) 
     end 
     end 
     traffic_source = URI::parse(full_traffic_source).host || "direct" 
    rescue Exception => e 
     Rails.logger.info "ERROR tracking ref link. #{e.message}" 
     traffic_source = "unknown" 
     full_traffic_source = "unknown" 
    end 

    # if I am registered from already, than use that for now (false or null use site) 
    registered_from = user.registered_from || "site" 
    if params && params[:controller] 
     registered_from = "quiz" if params[:controller].match(/quiz/i) 
     # registered_from = "api" if params[:controller].match(/api/i) 
    end 


    meta = { 
     :traffic_source => user.traffic_source || traffic_source, 
     :full_traffic_source => full_traffic_source, 
     :registered_from => registered_from, 
     :id_hash => user.get_id_hash 
    } 
    user.update_attributes(meta) 
    end 

end 
문제는 내가 나타났습니다한다

가능한 것 나던가 액세스 할 수 있음 쿠키 및 매개 변수는 스위퍼 내에서 해시되지만 일부 회사의 통합 환경에서는 정상적으로 나타납니다. 하지만 내 로컬 컴퓨터에서는 작동하지 않습니다. 그래서 내 질문 :

  1. 스위퍼 내에서 매개 변수/쿠키에 액세스하는 방법은 무엇입니까?
  2. 가능하지 않은 경우 어떻게 하시겠습니까?

감사

답변

0

난 아무것도 당신이 무엇을해야 넣어 그래서 만약 당신이 캐시 스위퍼에 세션 변수를 사용할 수 있습니다 확신하고

을 설정하고