帮助调试我的会话?Rails 3 ActionDispatch :: Cookies :: CookieOverflow

Ger*_*els 12 exception ruby-on-rails-3

虽然我很确定我知道为什么会出现这个错误,但我似乎不知道为什么或者我的会话超过了4KB的限制...

我的应用程序工作正常,但一旦我故意开始添加错误,看看我的交易是否回滚,我开始收到此错误.

为了给出一些背景知识,我正在忙着编写锦标赛应用程序(在本节中)将创建锦标赛,然后根据团队数量添加一些锦标赛分支,并在比赛中填入一些"幽灵装置"腿已经创建.

flash [:tournament]之前正常运作; 使用锦标赛对象,我可以访问任何AR验证错误以及在上一页输入的数据来创建锦标赛.

TournamentController.rb

begin
  <other code>
  Tournament.transaction do
    tournament.save!
    Tournament.generate_legs tournament
    Tournament.generate_ghost_fixtures tournament
  end

  flash[:notice] = "Tournament created!"
  redirect_to :action => :index
rescue Exception => e
  flash[:tournament] = tournament
  redirect_to :action => :new, :notice => "There was an error!"
end
Run Code Online (Sandbox Code Playgroud)

Tournament.rb

self.generate_ghost_fixtures(tournament)
  <other code>
  #Generate the ghost fixtures
  #tournament_legs is a has_many association
  tournament_legs_array = tournament.tournament_legs

  tournament_legs_array.each do |leg|
    number_of_fixtures = matches[leg.leg_code]

    #For the first round of a 32 team tournament, this block will run 16 times to create the matches
    number_of_fixtures.times do |n|
      Fixture.creatse!(:tournament_leg_id => leg.id, :match_code => "#{leg.leg_code}-#{n+1}")
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我只能推测为什么我的会话变量超过4KB?我通过flash变量的锦标赛对象是否也可能包含所有关联?

一旦出现错误,这是我的会话转储.

希望这是足够的信息来帮助我:)

谢谢

会话转储

_csrf_token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
flash: {:tournament=>#<Tournament id: nil, tournament_name: "asd", tournament_description: "asdasd", game_id: 1, number_of_teams: 16, start_date: "2011-04-30 00:00:00", tournament_style: "single elimination", tournament_status: "Drafting", active: true, created_at: "2011-04-30 10:07:28", updated_at: "2011-04-30 10:07:28">}
player_id: 1
session_id: "4e5119cbaee3d5d09111f49cf47aa8fa"
Run Code Online (Sandbox Code Playgroud)

Pab*_*zzi 13

关于依赖关系,这是可能的.同样在会话中保存ActiveRecord实例不是推荐的方法.你应该只保存id.如果您在所有请求中都需要它,请使用before过滤器来检索它.

您可以在以下网址阅读更多信息:http://asciicasts.com/episodes/13-dangers-of-model-in-session