跳转到内容

Ruby on Rails/ActionController/Cookies

来自维基教科书,开放世界中的开放书籍

当然,您可以在 Rails 应用程序中使用 cookies。这与使用 参数会话 非常相似。考虑以下示例

def index
  #here we want to store the user name, if the user checked the "Remember me" checkbox with HTML attribute name="remember_me"
  #we have already looked up the user and stored its object inside the object-variable "@user"
 if params[:remember_me]
   cookies[:commenter_name] = @user.name
 else # Delete cookie for the commenter's name cookie, if any
  cookies.delete(:commenter_name)
 end
end
华夏公益教科书