Project

auto_set

0.0
No commit activity in last 3 years
No release in over 3 years
Automatically update a column from a relationship
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

auto_set

Build Status Coverage Status Code Climate

auto_set automatically update a column from a relationship in Rails.

Installation

You can use auto_set as a gem in Rails 4.

To use the gem version, put the following gem requirement in your Gemfile:

gem "auto_set"

Usage

Supposing you have 3 models: Project, Group and Task and when you create a task in a groupit need to be related also to project. So, to auto_set update task.project_id with group.project.id, you do this:

auto_set :project, :group

The is also another case where you have a code that can be entered by the user and you want to relate it to an id. Let's assume that Group has a column project_code and you want to set project_id with that project id:

auto_set :project, from: :code

Customizing

You can set different type of callback:

auto_set :column, :parent, before: :create

before can be used in both cases of use and it can be save (default), create or validation.

Compatibility

Tested with Rails 4.0.13 in Ruby 2.0.0

License

MIT License. Copyright 2011 29sul Tecnologia da Informação http://www.29sul.com.br/