# init.rb
class << ActiveRecord::Basedef map_select_options(display = :name, value = :id, o = {})
o = {:select => "#{display},#{value}",
:order => display}.update(o)
find(:all, o).map { |x| [ x.send(display) , x.send(value) ] }
end
end
# controller
@options = Model.map_select_options
# view
select :object, :attribute, @options
Examples: Findar
moduleFindardefself.included(receiver)
super
constants.each do |c|
receiver.extend eval(c) if eval(c).is_a? ModuleendendmoduleMiscFindersdef find_random(o = {})
o[:order] = 'rand()'
find :first, o
end
alias_method :random, :find_random
end
end
Examples: Acts as Authenticated
Author: Rick Olson
acts_as_authenticated is not really a typical plugin that modifies
Rails. It's more of a generator for the authentication methods. I
went with a generator because it's designed as a basic starting point
that will probably (and should be) modified to fit your app's exact
needs. .
generators
authenticated
templates
authenticated_generator.rb
USAGE
authenticated_mailer
authenticated_migration
CHANGELOG
init.rb
install.rb
README
Beyond here..
The Complete Guide to Rails Plugins
In what is currently a two-part series,
Geoffrey Grossenbach covers
a plethora of plugin related topics including basic and more advanced integration
of tests in part two.
Plugins page on wiki.rubyonrails.com
Provides information for the unitiated as well as functioning
as the 'official' Rails plugin repository. If you're looking for example
code to inspire and teach, this is a good place to start.
HowTosPlugins page on wiki.rubyonrails.com
Tutorials about general 'types' of plugins like "Acts as.." or plugins
which modify the core framework