Bart Braem
2006-Aug-31 13:06 UTC
DRY approach to views for password protected parts of a site
Hello, I''m working on a system that has a protected part. Users have to login in order to be able to go there. Now I was wondering how I should handle the layout in a DRY way. All pages have the same layout with a header that contains either a few options and a login part or the full stack of options. How should I code that layout in order to have a nice DRY layout? I want to avoid to do checks on being authenticated in every layout. I prefer to have a single template (with a fixed header and footer) for the entire site that would be "automagically" included and rendered for users that are authenticated and not authenticated at once. I guess this is a quite normal question but I can''t find an article that also discusses the layout organisation (ie which file should I place where). Bart --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Curtis Summers
2006-Aug-31 13:50 UTC
Re: DRY approach to views for password protected parts of a
> I prefer to have a single template (with a fixed header and footer) for the > entire site that would be "automagically" included and rendered for users that > are authenticated and not authenticated at once.I created a helper method (actually a controller method that I made available as a helper too) called logged_in? in my application controller, so I can do stuff like this in my layouts/views: <%= render(:partial => ''user/user_dashboard'') if logged_in? %> Pertinent parts from the application controller: class ApplicationController < ActionController::Base helper_method :logged_in? def logged_in? session[:user_id].nil? ? false : true end end -- 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 -~----------~----~----~----~------~----~------~--~---