Eric Gross
2006-Dec-20 02:40 UTC
flash vs session vs globale variable for storing referrer
In creating my app, Im trying to figure out the best way to save the page referrer information. So far I''ve been flashing the referrer information across pages using flash.keep. Im not using session because I heard that "sessions don''t scale well" or something like that. What''s the best way to store the referrer information. Why can''t we just use a global variable like $url_referrer. I understand that it isnt good to make global variables, but in this case, I will just be using it to referrer the user. I just have to make sure that I set it to the right value for the user. In any case, its a pain having to flash the variables, if I could just store one variable that just keeps getting overwritten. I would love to get anyones thoughts on this. Thanks in advance. Aryk -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Eric Gross wrote:> > In creating my app, Im trying to figure out the best way to save the > page referrer information. > > So far I''ve been flashing the referrer information across pages using > flash.keep. Im not using session because I heard that "sessions don''t > scale well" or something like that. > > What''s the best way to store the referrer information. Why can''t we just > use a global variable like $url_referrer. > > I understand that it isnt good to make global variables, but in this > case, I will just be using it to referrer the user. I just have to make > sure that I set it to the right value for the user. >Not sure I understand completely, but to log the referrer I would do the following: 1. detect when a new session is created 2. if new (first time), log the referrer to referrer_log otherwise do nothing Capturing the referrer at first visit will give you external referrers, in most cases. I am assuming you don''t want to log local referrers. If this is not what you want perhaps you can provide more detail. Long www.edgesoft.ca/blog/read/2 - rails articles --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Aryk Grosz
2006-Dec-20 19:00 UTC
Re: flash vs session vs globale variable for storing referre
Long, the scenario I''m refering to (no pun intended) is when I''m running the user through a series of webpages and at the end, I want to refer the person back to where they originally came from. So for example, If I''m viewing an album, and I click on a picture, I view the pic on a different screen, then if I click "delete" I get taken to a deletion confirmation screen. Then if the user deletes, it goes back to the album. Something like that... Currently I do stuff like: flash.keep(:referrer) flash[:referrer] = flash[:referrer]||request.env["HTTP_REFERER"] This is kind of annoying to have to put a method call in every action I want to keep the referrer in. Can I just use a global variable or a session. I heard sessions dont scale well though or something like that. Long wrote:> Eric Gross wrote: >> >> I understand that it isnt good to make global variables, but in this >> case, I will just be using it to referrer the user. I just have to make >> sure that I set it to the right value for the user. >> > Not sure I understand completely, but to log the referrer I would do the > following: > > 1. detect when a new session is created > 2. if new (first time), log the referrer to referrer_log otherwise do > nothing > > Capturing the referrer at first visit will give you external referrers, > in most cases. > I am assuming you don''t want to log local referrers. > > If this is not what you want perhaps you can provide more detail. > > Long > www.edgesoft.ca/blog/read/2 - rails articles-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 20, 12:00 pm, Aryk Grosz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Can I just use a global variable or a session. I heard sessions dont > scale well though or something like that.There is nothing wrong with using sessions. They are there to preserve state for a user between requests and that is exactly what you are trying to do. The one rule I''ve heard over and over is do not store ActiveRecord objects in the session, store the objects id instead. I think it''s always good to ask yourself "do I really need to store this in the session?". Setting a session variable can seem like an easy solution until your application becomes riddled with checks for various session variables. Take what you are trying to do with storing the referrer. Do you really not know where the user is coming from? Do you always want to send them back to the page they came from? Where do you send them if the referrer session variable is not set? Maybe you could put a menu on every page and let the user decide where they want to go next. Aaron --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Aryk Grosz wrote:> > Long, the scenario I''m refering to (no pun intended) is when I''m running > the user through a series of webpages and at the end, I want to refer > the person back to where they originally came from. >Ah, so the referrer is really local to your site.> So for example, If I''m viewing an album, and I click on a picture, I > view the pic on a different screen, then if I click "delete" I get taken > to a deletion confirmation screen. Then if the user deletes, it goes > back to the album. >Well in this scenario you know exactly what page (album) to bring the user back to after a delete. I don''t see any gain in trying to remember where the user came from, but that is just my opinion. You could mark the page where the user should return to in the session. For example session[:back] = ''/album'' when the user enters /album. Though you will have to watch out for the case where session[:back] is undefined (it could happen).> Something like that... > > Currently I do stuff like: > > flash.keep(:referrer) > flash[:referrer] = flash[:referrer]||request.env["HTTP_REFERER"] > > > This is kind of annoying to have to put a method call in every action I > want to keep the referrer in. > > Can I just use a global variable or a session. I heard sessions dont > scale well though or something like that. >I don''t see any problem storing numbers and strings in the session, even simple models such as user_profile. It should be fine as long as you don''t store say a collection of a particular model. The problem with global var is that you only have one place to hold the :back pages of multiple users, each could have a different :back page. Every user will be directed to the :back page that was last recorded, possibly by another user. Long --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Aryk Grosz
2006-Dec-21 01:32 UTC
Re: flash vs session vs globale variable for storing referre
> > The problem with global var is that you only have one place to hold the > :back > pages of multiple users, each could have a different :back page. Every > user will > be directed to the :back page that was last recorded, possibly by > another user. > > LongOh I c, so the global variables can change between users. Ok, I think I will just store session[:back]. Of course I will write a function just in case it is null. Aaron, to answer your question, I need won''t know where the user is coming from, he could potentially be coming from a search results page. Of course, if I know where they are supposed to go back to, then I will manually input that. Thanks guys. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---