Hey I just launched a new release of www.strongside.dk based on rails 1.1. The site is in danish so it wont make any sense to most of you. However, here at technique I want to share with you. Some of the pages on that site requires a lot of calculations, but the data is actually static. So these pages are cached. However, when a logged on user is viewing a cached page, we still want to show him links based on his profile. Enter, a litte rjs... 1. in my layout i have: <span id="login_links"> <a href="/account/login">Login</a> | <a href="/account/signup">Opret Profil</a> | </span> but when a user is logged in I want to replace these with a logout and a view profile link. 2. create a action and add a whatever.js route for it. I called my route "profile.js". Just below my navigation is call this action with <script src="/site/profile.js" type="text/javascript"></script> 3. implement the action def profile render :update do |page| if session[''user''] page.replace_html ''login_links'',:inline=>''<span><a href="/ account/logout">Log af</a></span> | <span><a href="/viewprofile">Min Profil</a></span> |'' end end end I know, I should use the url helpers for this... Anyways... When a page is shown on the site, it only contains the login and create profile links. It calls the rjs action through the profile.js import The rjs action checks if its an logged in user, if so, replace the login/ create profile links with logout/view profile. This technique is in part inspired by one shown previously at http:// caboo.se, but this one, using rjs is much simpler... Mikkel Bruun www.strongside.dk - Football Portal(DK) nflfeed.helenius.org - Football News(DK) ting.minline.dk - Buy Old Stuff!(DK) -- Posted with http://DevLists.com. Sign up and save your time!
Mikkel Bruun wrote:> However, when a logged on user is viewing a cached page, we still want > to show him links based on his profile. > > Enter, a litte rjs.......> When a page is shown on the site, it only contains the login and create > profile links. > It calls the rjs action through the profile.js import > The rjs action checks if its an logged in user, if so, replace the login/ > create profile links with logout/view profile.Interesting. I had been thinking about this problem myself. I have a couple of pretty expensive pages that I was thinking about removing the customizations from so that they would be served from the cache. The solution that I was contemplating was to move the customizations into partials. Then, I was thinking, that the main page would be cached, but the partials would be dynamically generated. Does anyone know 1) if my mental model of caching is even correct and 2) how the two approaches would compare? Thanks, Ray
page caching writes the view to an actual .html file in public, so its completely static and partials wouldnt help you. You might have more luck with fragment cache, but is you have a lot of data in the fragment, that might cause a problem??? On Tuesday, March 28, 2006, at 11:09 AM, Ray Baxter wrote:>Mikkel Bruun wrote: > >> However, when a logged on user is viewing a cached page, we still want >> to show him links based on his profile. >> >> Enter, a litte rjs... > >.... >> When a page is shown on the site, it only contains the login and create >> profile links. >> It calls the rjs action through the profile.js import >> The rjs action checks if its an logged in user, if so, replace the >>login/ >> create profile links with logout/view profile. > >Interesting. > >I had been thinking about this problem myself. I have a couple of pretty >expensive pages that I was thinking about removing the customizations >from so that they would be served from the cache. > >The solution that I was contemplating was to move the customizations >into partials. Then, I was thinking, that the main page would be cached, >but the partials would be dynamically generated. > >Does anyone know 1) if my mental model of caching is even correct and 2) >how the two approaches would compare? > >Thanks, > >Ray > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsMikkel Bruun www.strongside.dk - Football Portal(DK) nflfeed.helenius.org - Football News(DK) ting.minline.dk - Buy Old Stuff!(DK) -- Posted with http://DevLists.com. Sign up and save your time!
If I were you I would take a look at partial page caching. It looks something like: <% cache("file/path/here") do %> <%= render :whatever %> <% end %> This will cache whatever is in the block to the file given. If the file isn''t there, then it will create it and the output as needed. I use this method quite a bit since I have a header which changes when a user is logged in or not. It seems to work pretty well. -Nick On 3/28/06, Ray Baxter <ray@warmroom.com> wrote:> Mikkel Bruun wrote: > > > However, when a logged on user is viewing a cached page, we still want > > to show him links based on his profile. > > > > Enter, a litte rjs... > > .... > > When a page is shown on the site, it only contains the login and create > > profile links. > > It calls the rjs action through the profile.js import > > The rjs action checks if its an logged in user, if so, replace the login/ > > create profile links with logout/view profile. > > Interesting. > > I had been thinking about this problem myself. I have a couple of pretty > expensive pages that I was thinking about removing the customizations > from so that they would be served from the cache. > > The solution that I was contemplating was to move the customizations > into partials. Then, I was thinking, that the main page would be cached, > but the partials would be dynamically generated. > > Does anyone know 1) if my mental model of caching is even correct and 2) > how the two approaches would compare? > > Thanks, > > Ray > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >