Rails 应用程序中的 Cookie 溢出? [英] Cookie overflow in rails application?

查看:36
本文介绍了Rails 应用程序中的 Cookie 溢出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ActionDispatch::Cookies::CookieOverflow in UsersController#create

ActionDispatch::Cookies::CookieOverflow in UsersController#create

当我尝试打开页面时出现此错误.我不知道如何调试这个错误.您对这个问题有什么建议吗?

I have this error when I try to open the page. I do not know how to debug this error. Do you have any suggestion for this problem?

def create
  @user = User.new(params[:user])
  sign_in @user

  if @user.save
    @user.folders.create(:folder_name=>"Default Folder", :user_id=>@user.id)
    flash[:success] = "Welcome to Bunch<it>! "
    redirect_to @user
  else
    @title = "Sign up"
    render 'new'
  end
end


def sign_in(user)
  cookies.permanent.signed[:remember_token] = [user.id, user.salt]
  session[:current_user] = user
  current_user = user
end

推荐答案

您可以在 cookie 中存储的内容有 4kb 的限制,并且当 Rails 将您的对象转换为文本以写入 cookie 时,它​​可能大于那个限制.

You've got a 4kb limit on what you can store in a cookie, and when Rails converts your object into text for writing to the cookie its probably bigger than that limit.

Ruby on Rails ActionDispatch::Cookies::CookieOverflow 错误

Ruby on Rails ActionDispatch::Cookies::CookieOverflow error

这样就会出现这个CookieOverflow错误.

That way this CookieOverflow Error occurs.

解决这个问题的最简单方法是,您需要更改 session_store,不要使用 cookie_store.您可以通过示例使用 active_record_store.

The easiest way to solve this one is, you need change your session_store and don't use the cookie_store. You can use the active_record_store by example.

步骤如下

  1. 生成创建会话表的迁移

  1. Generate a migration that creates the session table

rake db:sessions:create

  • 运行迁移

  • Run the migration

    rake db:migrate
    

  • Modify config/initializers/session_store.rb from

    (App)::Application.config.session_store :cookie_store, :key => 'xxx'
    

    (App)::Application.config.session_store :active_record_store
    

  • 完成三个步骤后,重新启动您的应用程序.Rails 现在将使用会话表来存储会话数据,并且您将没有 4kb 的限制.

    Once you’ve done the three steps, restart your application. Rails will now use the sessions table to store session data, and you won’t have the 4kb limit.

    这篇关于Rails 应用程序中的 Cookie 溢出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆