When someone comments on my site, I would like to store the user''s name as a cookie, and display it the next time they return. I really don''t know how to do this. Does this use the cgi library? As most things with ruby, I would imagine it to be quite simple... could anyone post a code snippet as to how this would work??? Thanks... -- Posted via http://www.ruby-forum.com/.
Very small amounts of Googling produced this: http://blog.nanorails.com/pages/rails_1.1_cheat_sheet On Aug 14, 2006, at 6:58 PM, ry an wrote:> When someone comments on my site, I would like to store the user''s > name > as a cookie, and display it the next time they return. I really don''t > know how to do this. Does this use the cgi library? As most things > with ruby, I would imagine it to be quite simple... could anyone > post a > code snippet as to how this would work??? Thanks... > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
ry an wrote:> When someone comments on my site, I would like to store the user''s name > as a cookie, and display it the next time they return. I really don''t > know how to do this. Does this use the cgi library? As most things > with ruby, I would imagine it to be quite simple... could anyone post a > code snippet as to how this would work??? Thanks...Do you want to store it on the user''s machine or the server? If it simply storing a name as a cookie, you can use javascript or rails to write a cookie. In a controller method that will write the cookie, use: cookies[:cookie_with_name] = {:value => ''User Name'', :expires => 1.year.from_now} In a controller method that will remove the cookie, use: cookies.delete :cookie_with_name That should do it for setting and removing the cookie. Now you need to figure out how to extract the name from cookies[:cookie_with_name]. Bill -- Posted via http://www.ruby-forum.com/.
Ok, thanks. Does anyone know how to extract the cookie value? cookies[:cookie_with_name].value #??? Thanks... -- Posted via http://www.ruby-forum.com/.
since cookies is a hash: cookies[:cookie_with_name] 2006/8/15, ry an <rheath@ircwv.com>:> > Ok, thanks. Does anyone know how to extract the cookie value? > > cookies[:cookie_with_name].value #??? > > Thanks... > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Michael Siebert <info@siebert-wd.de> www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060815/569933fe/attachment.html