Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jodosha/nested_models

NestedModels deal with massive handling of associated (nested) ActiveRecord models.
https://github.com/jodosha/nested_models

Last synced: about 1 month ago
JSON representation

NestedModels deal with massive handling of associated (nested) ActiveRecord models.

Awesome Lists containing this project

README

        

NestedModels
============

Until now ActiveRecord wasn't great with associations massive assignment (aka multi model forms handling).
This plugin allow to deal with this kind of problems.

Example
=======

class Project < ActiveRecord::Base
has_many :tasks, :accessible => true
end

# CREATE
project = Project.create :name => "NestedModels", :tasks => [
{ :name => "Implement", :description => "Implement me" }
]

project.name # => "NestedModels"
project.taks.size # => 1

# UPDATE
project.update_attributes :tasks => [
{ :id => 1, :name => "Implement me" },
{ :name => "Evangelize", :description => "Tell to your friends!" }
]

project.tasks.size # => 2
project.tasks.first.name # => "Implement me"
project.tasks.last.name # => "Evangelize"

# DESTROY
project.update_attributes :tasks => [
{ :id => 1, :destroy => true }
]

project.tasks.size # => 1

Note: you can define your own destroy flag:
class Milestone < ActiveRecord::Base
set_accessible_association_destroy_flag "destroy_me"
end

project.update_attributes :milestones => [
{ :id => 1, :destroy_me => true }
]

Copyright (c) 2009 Luca Guidi, released under the MIT license