I''m playing with caching, and since my site contians a "login and register" link, which only should be shown when the user isn''t logged in, page-caching is not an option :/ but what about action-caching? the to links are placed in layout/application.rhtml, but they are still being cached :/ shouldn''t caches_action only cache the output of the action i use i on? -- 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 -~----------~----~----~----~------~----~------~--~---
Hey Henrik Jensen wrote:> I''m playing with caching, and since my site contians a "login and > register" link, which only should be shown when the user isn''t logged > in, page-caching is not an option :/ >I thought the same thing a while ago, but then I played around with it a bit and eventually javascript semi-solved the problem. By saving an additional cookie in users'' browser - one which only existed while they were logged in - I used javascript to check for it (findiing it meaning they were logged in) and changing tiny bits of my layout, eg the login link to a logout link if the cookie existed. Here''s the code: In the view: <%= link_to ''login'', ''/login'', :id => ''login_link'' %> <%= update_page_tag do |page| exec_this = " if (getCookie(''logged_in'') { $(''login_link'').href = ''/logout''; $(''login_link'').innerHTML = ''logout'';" }" page << exec_this end %> The javascript looks as follows and I got it from a website sometime, I think...so kudos to whoever wrote it! I think it returns the actual value of the cookie, so you can use that if you''d like. Just put this in your application.js, or in <script> tags... //************************************************************* function getCookie(name) { var dc = document.cookie; var prefix = name + "="; var begin = dc.indexOf("; " + prefix); if (begin == -1) { begin = dc.indexOf(prefix); if (begin != 0) return null; } else begin += 2; var end = document.cookie.indexOf(";", begin); if (end == -1) end = dc.length; return unescape(dc.substring(begin + prefix.length, end)); } //*************************************************************> but what about action-caching? the to links are placed in > layout/application.rhtml, but they are still being cached :/ shouldn''t > caches_action only cache the output of the action i use i onI don''t think this''ll work for very large modifications, but if the only thing holding you back from page caching is one or two <a>''s, give this a shot and see if it works for you... Hope you find this useful! Cheery-o! Gustav Paul gustav-PUm+PnBUKx7YkQIYctQFYw@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> By saving an additional cookie in users'' browser - one which only > existed while they were logged in - I used javascript to check for it > (findiing it meaning they were logged in) and changing tiny bits of my > layout, eg the login link to a logout link if the cookie existed.I guess that would work - however I have to admit it''s ugly, and I would prefer not to use it :) Is there really no other way to only catch the returnvalue of an action? -- 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 -~----------~----~----~----~------~----~------~--~---
Henrik Jensen wrote:>> By saving an additional cookie in users'' browser - one which only >> existed while they were logged in - I used javascript to check for it >> (findiing it meaning they were logged in) and changing tiny bits of my >> layout, eg the login link to a logout link if the cookie existed. >> > > I guess that would work - however I have to admit it''s ugly, and I would > prefer not to use it :) > > Is there really no other way to only catch the returnvalue of an action? > >Lol, I preferred not to use it either in the end :) Nope, I don''t know of any other way. This bugged me as well, but I couldn''t find any other way :( Sorry man, Gustav Paul gustav-PUm+PnBUKx7YkQIYctQFYw@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You might be better served with the action_cache plugin, http:// agilewebdevelopment.com/plugins/action_cache, which can use any variables available to the app (such as logged-in status) to create alternate cached versions of the same action. -- Building an e-commerce site with Rails? http://www.agilewebdevelopment.com/rails-ecommerce On Nov 10, 2006, at 9:25 AM, Gustav Paul wrote:> > Hey > > Henrik Jensen wrote: >> I''m playing with caching, and since my site contians a "login and >> register" link, which only should be shown when the user isn''t logged >> in, page-caching is not an option :/ >> > I thought the same thing a while ago, but then I played around with > it a > bit and eventually javascript semi-solved the problem. > > By saving an additional cookie in users'' browser - one which only > existed while they were logged in - I used javascript to check for it > (findiing it meaning they were logged in) and changing tiny bits of my > layout, eg the login link to a logout link if the cookie existed.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---