This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
Erik Peterson (author)
Tue Jul 22 18:28:53 -0700 2008
commit 57b34e3d5f1ff420048268ac628d453acc643c0d
tree 64f9940663831cfa31dafdbebe64b21d2a064270
parent 741849da1544f3396c14bba0a2121ceeedfacff0
tree 64f9940663831cfa31dafdbebe64b21d2a064270
parent 741849da1544f3396c14bba0a2121ceeedfacff0
| name | age | message | |
|---|---|---|---|
| |
.gitmodules | ||
| |
LICENSE | ||
| |
README.rdoc | ||
| |
Rakefile | ||
| |
example_app/ | ||
| |
generators/ | ||
| |
init.rb | ||
| |
install.rb | ||
| |
lib/ | ||
| |
meta.yml | ||
| |
test/ | ||
| |
uninstall.rb |
README.rdoc
acts_as_referenced
acts_as_referenced is an easy way to implement unique reference numbers across many different models.
Installation
If you are on edge rails:
script/plugin install git://github.com/subwindow/acts_as_referenced.git
If you are not on edge rails:
git clone git://github.com/subwindow/acts_as_referenced.git vendor/plugins/acts_as_referenced
Usage
To make use of acts_as_referenced, you first need to create the Reference model & its table:
script/generate reference reference rake db:migrate
You also need a column ‘reference’ in all of the tables you plan on using acts_as_referenced with. (You can change this with the :referenced_column option)
Enable the functionality by declaring acts_as_referenced on your model
class Order < ActiveRecord::Base
acts_as_referenced
end
Advanced Usage
Advanced usage is enabled through a set of options. Here they are:
# Separator
acts_as_referenced # Defaults to '-', e.g.: '080722-1'
acts_as_referenced :separator => "" #e.g.: '0807221'
acts_as_referenced :separator => "_" #e.g.: '080722_1'
# Prefix. A string that is appended at the front of the reference number. Does not affect incrementing. Accepts a proc.
acts_as_referenced # Defaults to '', e.g.: '080722-1'
acts_as_referenced :prefix => "OR" # e.g.: "OR-080722-1"
acts_as_referenced :prefix => Proc.new {|o| o.category.first.upcase } # e.g.: "M-080722-1"
# Increment base. A string that is used as the base for incrementing- all reference numbers with the same base will be incremented together. Accepts strftime arguments.
acts_as_referenced # Defaults to "%y%m%d", e.g.: "080722-1"
acts_as_referenced :increment_base => "#{(65+(Time.now.year-2003)).chr}%m%d" # e.g.: "F0722-1"
# Increment size. An integer that is used to pad incrementers. Useful if you require reference numbers with a consistent legnth.
acts_as_referenced # Defaults to 0, e.g.: "080722-1", "080722-9999"
acts_as_referenced :increment_size => 4 #e.g.: "080722-0001", "080722-9999"
# Referenced Column. Change the name of the "reference" column that is stored on the model.
acts_as_referenced # Defaults to 'reference'
acts_as_referenced :referenced_column => "order_number"
Copyright © 2008 Erik Peterson, released under the MIT license








