New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kriss-associated_records_on_steroids

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kriss-associated_records_on_steroids

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Plugin allowing to auto build and validate associated records and merge validation errors

== Examples

If you want automatically build specified associated recrods when new record is initialized you can use auto_build:

class Bar < ActiveRecord::Base belongs_to :foo end

class Foo < ActiveRecord::Base has_one :bar set_associated_records_to_auto_build :bar end

foo = Foo.new foo.bar # => #Bar:0x...

You can also validate associated record in easy way:

class Person < ActiveRecord::Base has_one :address validates_presence_of :name validates_associated_record :address delegate :street, :street=, :city, :city=, :state, :state=, :zip, :zip=, :to => :address end

class Address < ActiveRecord::Base validates_presence_of :street, :city, :state, :zip end

joe = Person.new joe.valid? # => false

joe.errors.on(:name) # => "can't be blank" joe.errors.on(:street) # => "can't be blank" joe.errors.on(:city) # => "can't be blank" joe.errors.on(:state) # => "can't be blank" joe.errors.on(:zip) # => "can't be blank"

And of course merging errors in not associated records:

class Person < ActiveRecord::Base validates_presence_of :name end

class Address < ActiveRecord::Base validates_presence_of :street, :city, :state, :zip end

joe = Person.new joe.valid? # => false address = Address.new address.valid? # => false

joe.errors.merge address.errors joe.errors.on(:name) # => "can't be blank" joe.errors.on(:street) # => "can't be blank" joe.errors.on(:city) # => "can't be blank" joe.errors.on(:state) # => "can't be blank" joe.errors.on(:zip) # => "can't be blank"

Enjoy!

FAQs

Package last updated on 11 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc