[Rails] Design question - integrating light-weight authorization

Jarkko Laine jarkko at jlaine.net
Wed Nov 24 14:54:26 GMT 2004


On 24.11.2004, at 15:24, Vincent Foley wrote:

> I don't know about the others, but I think the way I would do it would
> be to have multiple views with a certain naming pattern.  If you have
> users and admins in your system, your mainmenu.rhtml could instead be
> two files named admin_mainmenu.rhtml and user_mainmenu.rhtml and have
> something in your controller like:
>
> def index
>   render_file "#{user.klass}_mainmenu.rhtml"
> end

I disagree if you mean that you'd render totally different files  
depending on the user class. Why? DRY. If most parts of the pages are  
identical, you'd end up repeating the same html code in two places,  
potentially vulnerable to change-one-forget-the-other mistakes.

If, however, you mean rendering a partial, I heartily agree. Then you'd  
have the differing parts (e.g. a navigation bar) in partials and you'd  
render the one needed. I feel that obeys a bit better the DRY  
principle.

One possible way to tackle this problem is using layouts (described  
here:  
http://api.rubyonrails.org/classes/ActionController/Layout/ 
ClassMethods.html).

Just my two cents.

//jarkko

--
Jarkko Laine
http://jlaine.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2363 bytes
Desc: not available
Url : http://one.textdrive.com/pipermail/rails/attachments/20041124/bc00cc35/smime.bin


More information about the Rails mailing list