问题
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