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

GetOrBuild

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

GetOrBuild

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

GetOrBuild

This is a association builder which helps to generate or get associated object with belogs_to or has_one association.

##Installation

Add this line to your Gemfile gem 'get_or_build' then as usually update installed gem by typing bundle in terminal.

Using with ActiveRecord

Assume you have model Company which has one User and belongs to Location:

class Company < ActiveRecord::Base
	belongs_to :location
	has_one :user
	accepts_nested_attributes_for :user
	accepts_nested_attrbiutes_for :location
end

class User < ActiveRecord::Base; end
class Location < ActiveRecord::Base; end

When you are building form for company with nested attributes for location or user you are able now use new methods like user_or_build or location_or_build:

form_for :company do |f|
	f.fields_for :user, f.object.user_or_build do |fu|
		fu.text_field :name
	f.fields_for :location, f.object.location_or_build do |fl|
		fl.text_field :address
		

No longer need to call f.object.user || f.object.build_user

Using with NoSQL databases

Just include in your document module GetOrBuild::AssociationBuilder and it will attach magick methods automatically

Contributing

You are welcome! Please, run test before pull request: ruby test/*.rb and make sure if everything is workig correctly.

TODO

  • tests for MongoMapper

FAQs

Package last updated on 22 Mar 2012

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