views:

43

answers:

3

I am relatively new to Rails and recently found a couple of useful gems like authlogic that will help in getting the project up and about really fast. However, I have been wondering where to place the model, view, and controller files that are dependent on the plugin, but are core concepts of my project.

For example, is it better to place the User, Role, Session, etc.. models and related controllers with the plugin inside the vendor/ directory, or should I place them inside the root model/, view/, and controllers/ directories respectively?

+2  A: 

Even models/views/controllers dependent on plugins should be kept in the app/model, app/view, and app/controllers directories along with your other code.

The "structural" reason is that the bulk of all those files will still be specific to your application. You will probably end up adding fields to the user, or adding has_many statements to your User model, etc. You want all that code with the rest of your core application code in the app directory.

The "functional" reason is that vender/plugins is only for the code specifically relating to that plugin and is treated differently during development. For instance, when you add a new plugin, it is not auto-loaded in development mode. So if your core files were there, they would not be auto reloaded even in development mode.

Doug Neiner
that makes a lot of sense from both perspectives. the reason i was stuck was because these plugins can easily be modified or extended in ruby owing to the language features, and the line between the plugin and custom code started to blur for me.
Anurag
@Anurag it can get confusing. Even more confusing is if you are writing code for *your* app, you keep it in the `app` directory. If you are modifying the way the *core plugin* acts, you normally put those changes in `lib` following a special folder/file naming pattern so the actual plugin can still be upgraded from the source, and your changes are still separate.
Doug Neiner
+1  A: 

Anything you write should be in the standard directories. Use vendor for vendor-provided code.

JRL
+1  A: 

Just as a heads up it is very hard to go wrong watching railscasts on topics you are new to.

Ryan Bates has two covering authlogic and authlogic with OpenID and in anticipation of your next step after authentication- authorization: He has some covering access control as well: Declarative Authorization, and CanCan.

srboisvert