Rails Set a Cookie to ensure gets a Javascript message only once
I am trying to set a cookie so that users only get a javascript only once. However, I am a Rails newbie and have no idea where to begin. Can anyone point in me in th开发者_开发知识库e right direction?
If it's Javascript you're concerned about I would manage the cookie entirely in Javascript. After the message is shown the first time, set the cookie. It's relatively easy to work with cookies in native Javascript, but libraries like this make it a no-brainer: http://code.google.com/p/cookies/ . You could also use localStorage.
Or you're talking about the inclusion of an actual script only one time? You could do this via Rails with a session ( http://www.quarkruby.com/2007/10/21/sessions-and-cookies-in-ruby-on-rails ), or just make that script a function that gets called or ignored based on whether a cookie has been set.
精彩评论