rails 3 cookies

泪湿孤枕 提交于 2020-01-03 21:04:11

问题


I have a simple app where users type in stuff in a text filed to get various results. I would like a feature where if a user enters something and then closes the browser tab, the next time they come, I can show them their previous/recent searches. This will persist even if they close the whole browser and open it again.

I believe this can be done by help of cookies. Are there some good rails3 gems for using cookies or any simple tutorial that could guide me in a direction?


回答1:


http://railstutorial.org/chapters/sign-in-sign-out#sec:remember_me

This is a great book to get you started with rails3. (I would recommend to read it from the beginning)

In the link above, listing 9.12 gives you a good explanation about cookies.




回答2:


Store the info in the session object:

session[:user_entry] = the_user_entry

http://guides.rubyonrails.org/action_controller_overview.html#session



来源:https://stackoverflow.com/questions/4576875/rails-3-cookies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!