问题描述
UsersController#create 中的 ActionDispatch::Cookies::CookieOverflow
当我尝试打开页面时出现此错误.我不知道如何调试此错误.您对这个问题有什么建议吗?
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
就会发生错误.
解决这个问题的最简单方法是,您需要更改 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.
步骤如下
生成创建会话表的迁移
Generate a migration that creates the session table
rake db:sessions:create
运行迁移
Run the migration
rake db:migrate
修改 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溢出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!