= ModelCrumb
This plugin provides ActiveRecord based breadcrumbs for your users so
that they will have a list of the last n visited items on your website.
Using a relational database store for crumbs provides you with a way
to keep your crumbs from getting moldy. When models are edited, deleted
, etc. The crumbs will follow. The ModelCrumbSystem library is provided
with a 'drop_crumb' method that can either be used as a after_filter or
directly in your controller. You will need to provide a model class,
an id attribute, and optionally a URI string for the requested object.
== Installation
If your project is source-controlled by Subversion (which it should be, really),
the easiest way to install this is via Rails' plugin script:
./script/plugin install -x http://svn.webwideconsulting.com/svn/model_crumb/trunk
If you're not using Subversion, or if you don't want it adding
svn:externals in your project, remove the -x switch:
./script/plugin install http://svn.webwideconsulting.com/svn/model_crumb/trunk
== Setting Up
You will need to generate the crumb model.
./script/generate model_crumb crumb
You will want to rake the new migration
rake db:migrate
Add this to your user model (release version will be a mixin):
has_many :crumbs, :order => 'created_at ASC', :dependent => :destroy
And this to any model which you will be crumbing (again mixin later):
has_many :crumbs, :as => :target, :dependent => :destroy
== Usage
To "drop a crumb" when a Post model is viewed, you can do something like this. I really
want to make this is to a cleaner direct method, but this works for now:
include ModelCrumbSystem
after_filter :only => [:show] do |c|
c.drop_crumb :target => Post, :id => c.params[:id], :uri => c.request.request_uri
end
== Todos
* Cleaner methods for usage as a filter
* Remove hardcoded limit from the crumb model
* Use the library directly from the plugin instead of a generator
* Provide a User mixin, and/or templates for a specific user association attribute.
* Ability to add non-model specific crumbs as needed.
* Mixin for models that will be used for crumb association
== Credits
Written by Josh Martin . Released under the MIT License.