1

イベントをセッション変数に保存し、次のページのkissmetrics JavaScriptコードに渡すことで、RailsアプリにKissmetricsをインストールしています。この方法は、作成されたアカウントを追跡しようとすることを除いて、うまく機能します. アカウント作成イベントをセッション変数に保存すると正常に動作するようですが、次のページが読み込まれるまでにセッション変数は消えています。そこにデバッガーを入れて、削除されている場所を見つけようとしましたが、何もないようです。km_log_event は、文字列を km_events というセッション変数に格納するメソッドです。これが私のコードです:

accounts_controller/create -->

...    
if @account.save 
            log_event("Account", "Created", @account.name)
            km_log_event("Account Created")
            redirect_to(welcome_url(:subdomain => @account.subdomain)) 
            @user.activate!
            @user.add_connection(params[:connect_to])
          else
            render(:action => 'new', :layout => 'signup')
          end
...

sessions_controller/ようこそ -->

def welcome
    if current_account.new?
      # Create the session for the owner, the account is brand new
      current_account.user_sessions.create(current_account.owner, true)
    elsif current_account.users.last && current_account.users.last.created_at > 1.hour.ago
      current_account.user_sessions.create(current_account.users.last, true)
    end
    redirect_to embedded_invitations_path
  end

どこで削除されているのかわからないので、このイベントを記録できません。アカウントコントローラーの @account.save の後、ウェルカムアクションの前に発生しているようです。

アップデート:

これは、 current_account が定義されると私が信じているアカウントモジュールです (これは私のコードベースではありません)。

module Accounts
    def self.included(controller)
        controller.helper_method :current_account
    end

    protected

        def current_account
            return @current_account if defined?(@current_account)
            @current_account = Account.find_by_subdomain!(current_subdomain)
        end
end
4

2 に答える 2

3

無効な csrf トークンにより、セッションがリセットされます。これが起こっている可能性はありますか?

これは、コントローラーから以下を削除することで簡単にテストできます (通常は ApplicationController にあります)。

  protect_from_forgery
于 2012-02-19T19:52:41.173 に答える
0

サブドメイン間でセッションを共有しようとしているときに、これが起こっていると思います。これを実現するには、いくつかの構成を行う必要があります。

カスタム ドメインの有無にかかわらず、Heroku の Rails 2.3 および Rails 3 でサブドメイン セッションが機能しないことを参照してください。

于 2012-02-20T10:12:09.100 に答える