Advanced Validations plugin

Plugin details

this plugin is intented to patch the problem of validations when done for scope.
see Rails Trac ticket 8774 (http://dev.rubyonrails.org/ticket/8774)

Repositoryhttp://adv-validations.rubyforge.org/svn/advanced_validations Author Peeyush Aggarwal Tags Database, Validations, ActiveRecord LicenseLGPL

Documentation

Install the plugin:
ruby script/plugin install http://adv-validations.rubyforge.org/svn/advanced_validations
        class Product < ActiveRecord::Base

          has_many :product_attributes
          validates_associated_advanced :product_attributes

        end

        class ProductAttribute < ActiveRecord::Base

          belongs_to :product

          validates_uniqueness_of_advanced :position, :scope => [:product_id]

        end


open script/console in your rails application

   p = Product.new(:MPN => "324234", :name => "good", :weight => "32", :manufacturer_id => "0", :short_description => "b", :long_description => "b", :UPC => "23423423", :SKU => "asf232")

        >> pa = ProductAttribute.new(:position => 1, :key => "b", :value => "b", :value_unit_id => "1", :value_type_id=>"1", :value_array => "false")

        >> pa.product = p

        >> p.product_attributes << pa
        >> p.product_attributes << pa #2nd attribute with same position value

        >> p.valid?
        => false

        >> p.save
        => false

        >> p.errors.full_messages
        => ["Product Attribute is invalid"]

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: Guest, 5 months ago