normalize article and category attributes (closes foodcoops#294)
This commit is contained in:
parent
7c2ecd8658
commit
a43020463d
5 changed files with 18 additions and 0 deletions
1
Gemfile
1
Gemfile
|
@ -41,6 +41,7 @@ gem 'resque'
|
|||
gem 'whenever', require: false # For defining cronjobs, see config/schedule.rb
|
||||
gem 'protected_attributes'
|
||||
gem 'ruby-units'
|
||||
gem 'attribute_normalizer'
|
||||
|
||||
# we use the git version of acts_as_versioned, and need to include it in this Gemfile
|
||||
gem 'acts_as_versioned', git: 'git://github.com/technoweenie/acts_as_versioned.git'
|
||||
|
|
|
@ -80,6 +80,7 @@ GEM
|
|||
acts_as_tree (1.6.1)
|
||||
activerecord (>= 3.0.0)
|
||||
arel (4.0.2)
|
||||
attribute_normalizer (1.1.0)
|
||||
better_errors (1.1.0)
|
||||
coderay (>= 1.0.0)
|
||||
erubis (>= 2.6.6)
|
||||
|
@ -398,6 +399,7 @@ PLATFORMS
|
|||
DEPENDENCIES
|
||||
acts_as_tree
|
||||
acts_as_versioned!
|
||||
attribute_normalizer
|
||||
better_errors
|
||||
binding_of_caller
|
||||
bootstrap-datepicker-rails
|
||||
|
|
|
@ -45,6 +45,8 @@ class Article < ActiveRecord::Base
|
|||
|
||||
# Replace numeric seperator with database format
|
||||
localize_input_of :price, :tax, :deposit
|
||||
# Get rid of unwanted whitespace. {Unit#new} may even bork on whitespace.
|
||||
normalize_attributes :name, :unit, :note, :manufacturer, :origin, :order_number
|
||||
|
||||
scope :undeleted, -> { where(deleted_at: nil) }
|
||||
scope :available, -> { undeleted.where(availability: true) }
|
||||
|
|
|
@ -10,6 +10,8 @@ class ArticleCategory < ActiveRecord::Base
|
|||
# @return [Array<Article>] Articles with this category.
|
||||
has_many :articles
|
||||
|
||||
normalize_attributes :name, :description
|
||||
|
||||
validates :name, :presence => true, :uniqueness => true, :length => { :in => 2..20 }
|
||||
|
||||
before_destroy :check_for_associated_articles
|
||||
|
|
11
config/initializers/attribute_normalizer.rb
Normal file
11
config/initializers/attribute_normalizer.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# config/initializers/attribute_normalizer.rb
|
||||
# @see https://github.com/mdeering/attribute_normalizer
|
||||
AttributeNormalizer.configure do |config|
|
||||
# The default normalizers if no :with option or block is given is to apply the :strip and :blank normalizers (in that order).
|
||||
# You can change this if you would like as follows:
|
||||
# config.default_normalizers = :strip, :blank
|
||||
|
||||
# You can enable the attribute normalizers automatically if the specified attributes exist in your column_names. It will use
|
||||
# the default normalizers for each attribute (e.g. config.default_normalizers)
|
||||
# config.default_attributes = :name, :title
|
||||
end
|
Loading…
Reference in a new issue