NestedModels deal with massive handling of associated (nested) ActiveRecord models.
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 4 commits ahead of jodosha:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
tasks
test
CHANGELOG
MIT-LICENSE
README
Rakefile
init.rb
install.rb
nested_models.gemspec
uninstall.rb

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