<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.6.2">
</HEAD>
<BODY>
It's not really a module, it's just a directory. What you can do is create a controller with all of the functionality you need and then have each one of your "secure" controllers inherit from that. ie <BR>
class SecureController < Admin<BR>
<BR>
If you do this you get all of the normal controller stuff pluss whatever you have in the admin controller<BR>
<BR>
On Wed, 2006-05-31 at 17:35 +0200, Paul Butcher wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">I am aware that controllers can be placed in modules:</FONT>
<FONT COLOR="#000000"> ruby script/generate controller modulename/controllername</FONT>
<FONT COLOR="#000000">But what does this buy me? Is it just a way of ensuring that my source </FONT>
<FONT COLOR="#000000">code is nicely arranged, or can I use the fact that a set of controllers </FONT>
<FONT COLOR="#000000">are all within a particular model to implement functionality common to </FONT>
<FONT COLOR="#000000">all of those controllers?</FONT>
<FONT COLOR="#000000">Why am I asking?</FONT>
<FONT COLOR="#000000">The app we're currently working on has some controllers which can be </FONT>
<FONT COLOR="#000000">accessed by anyone and some which require the user to login before they </FONT>
<FONT COLOR="#000000">can access it. Currently we have</FONT>
<FONT COLOR="#000000"> before_filter :login_required</FONT>
<FONT COLOR="#000000">at the top of each "secure" controller. I would like to separate secure </FONT>
<FONT COLOR="#000000">controllers into one module and unsecure controllers in another. I </FONT>
<FONT COLOR="#000000">thought that this might give me a way to DRY the code up - by having the </FONT>
<FONT COLOR="#000000">secure module enforce the login requirement. But if there is a way to </FONT>
<FONT COLOR="#000000">achieve this, it's escaping me.</FONT>
<FONT COLOR="#000000">I can obviously achieve the desired effect through inheritance, as </FONT>
<FONT COLOR="#000000">described here:</FONT>
<FONT COLOR="#000000"><A HREF="http://justinfrench.com/index.php?id=122">http://justinfrench.com/index.php?id=122</A></FONT>
<FONT COLOR="#000000">But this requires me to remember to change the base class of each new </FONT>
<FONT COLOR="#000000">secure controller (and raises the spectre of having a controller in the </FONT>
<FONT COLOR="#000000">secure module which doesn't inherit from the appropriate base).</FONT>
<FONT COLOR="#000000">Am I missing something?</FONT>
<FONT COLOR="#000000">Thanks!</FONT>
<FONT COLOR="#000000">paul.butcher->msgCount++</FONT>
</PRE>
</BLOCKQUOTE>
<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
Charlie Bowman<BR>
http://www.recentrambles.com
</TD>
</TR>
</TABLE>
</BODY>
</HTML>