标签:class blog code com 使用 2014
Rails通过cookies方法来操作cookie,这和session的操作有点类似
class CommentsController < ApplicationController
def new
# 假如cookie中有评论者的姓名,则自动调用
@comment = Comment.new(author: cookies[:commenter_name])
end
def create
@comment = Comment.new(params[:comment])
if @comment.save
flash[:notice] = "Thanks for your comment!"
if params[:remember_name]
# 设置cookie
cookies[:commenter_name] = @comment.author
else
# 删除cookie中的变量
cookies.delete(:commenter_name)
end
redirect_to @comment.article
else
render action: "new"
end
end
end
Rails Cookie和session使用,布布扣,bubuko.com
标签:class blog code com 使用 2014
原文地址:http://blog.csdn.net/thinkdiff/article/details/33284007