Rails: Where to place plugin files - ruby-on-rails

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?

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.

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

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.

Related

finding a ruby gem for config settings that can be updated from web interface

I am creating a rails web app that is a really a content management system. Thus there is going to be a admin section of the app. There I want users to be able to set config setting that are available through the app. Thus I want basic CRUD functionality for config settings. (If you've ever used the admin section of the Discourse discussion board, you'll know what I want to do)
Most of the config gems I have seem to be about organizing config info during development, but seem to expect that config info to be basically set and static on production. (See How to define custom configuration variables in rails)
However, in the above link there was one gem called rails-settings (https://github.com/Squeegy/rails-settings) that, in its description, seemed very close to what I want. However, it seems very old (last commit was 2009).
Three related questions:
1) Is there is a standard Gem for this kind of thing that I'm missing?
2) Should I use rails-settings?
3) Should I just create my own model called Settings < ActiveRecord and would this model be available throughout all my controllers?

Can multiple Rails Applications share models/common business domain data between them?

I have several use cases that manipulate and add to the same data at different points in the process.
Each of these use cases share many of the same models, and actions in the process but would require totally different views and structure.
I was thinking of trying out the tips in this article from 8thLight but this was written in 2007.
http://blog.8thlight.com/jim-suchy/2007/02/20/sharing-a-database-among-multiple-rails-applications.html
According to them, the trick is to
(1) make a new folder with the shared models right above the application.
applications_in_same_business_domain
|-shared_models
|-application1
|-application2
|-...
(2) require this new folder or module in your application via enviorments.rb file
(which I believe the equivalent would be config/application.rb because I don't see enviornments.rb in Rails 3.)
They say some code like this will work (in environments.rb)
$: << File.dirname(__FILE__) + '/your_lib_path'
I tried this and it isn't working (in application.rb)...
config.autoload_paths += %W(../../../mardom_shared_models)
Is this the standard way to do this?
An API sounds like another way to do this...but...I don't know anything about API's here. Self-learning 6-Month Noob here)
Helping me get the above to work if it is possible I guess would be the specific question. Can I do this?
But any comments or articles on other matter would be appreciated.
I would need to modify the Rails generators here starting from this link: http://guides.rubyonrails.org/generators.html
I would rather put all models related stuff into a gem, and install gem locally to vengor/gems directory to simplify navigating in it.

Why rails doesn't want you to create rails projects within existing rails project

I want to create another project inside exisiting rails app. My reasoning is that:
They have some common models which I would be able to link to from the inner app,
They operate on the same database
They will have one version control system (no additional configuration and moving required)
Apart from why I want to do that I just want to know why rails prevents you from doing that? As of my testing, no conflicts were exposed.
You should be using Rails Engines for this. Here's a Railscasts episode about it. http://railscasts.com/episodes/149-rails-engines

Looking for something like RailsAdmin, but lighter-weight and not in the same process as the main app

We've been using rails_admin for a project for a year. It's good, but it would be preferable to have an admin interface that ran in a totally separate process from the main Rails app and from a completely independent code base. rails_admin has so many dependencies that upgrading it along with the main Rails app has proven brittle.
So the functionality we would need is just basic crud for the database tables, with a little bit of magic to make editing associations easier.
Are there any light-weight solutions out there for this? Bonus points for being lightweight & Sinatra-based rather than Rails-based.
I would look into git submodules or subversion externals. The way I've done something similar to this is to
List item migrate the models into a standalone ruby project.
put them in a 'core' subdirectory/module.
Create a new rails project just for administration.
Share the models between the 2 rails apps using an svn external of the 'core' directory into each project's app/models directory.

Building an extension framework for a Rails app

I'm starting research on what I'd need in order to build a user-level plugin system (like Wordpress plugins) for a Rails app, so I'd appreciate some general pointers/advice. By user-level plugin I mean a package a user can extract into a folder and have it show up on an admin interface, allowing them to add some extra configuration and then activate it.
What is the best way to go about doing this? Is there any other opensource project that does this already? What does Rails itself already offer for programmer-level plugins that could be leveraged? Any Rails plugins that could help me with this?
A plugin would have to be able to:
run its own migrations (with this? it's undocumented)
have access to my models (plugins already do)
have entry points for adding content to views (can be done with content_for and yield)
replace entire views or partials (how?)
provide its own admin and user-facing views (how?)
create its own routes (or maybe just announce its presence and let me create the routes for it, to avoid plugins stepping on each other's toes)
Anything else I'm missing?
Also, is there a way to limit which tables/actions the plugin has access to concerning migrations and models, and also limit their access to routes (maybe letting them include, but not remove routes)?
P.S.: I'll try to keep this updated, compiling stuff I figure out and relevant answers so as to have a sort of guide for others.
You might want to check out mephisto, it's a blogging software built with ruby on rails and has add-on plugin support. Not sure if it works how you are thinking of, but might give you some good insights. The source can be found on GitHub.
You should look at deface gem. It allows to customize rails views, adding content via hooks and replacing whole views/partials. Spree is using this gem so you can look also at spree. Beside views they also have other solutions for customizing application so you can find more answers to your questions.

Resources