Skip to content

An easy way to Create/Update/Destroy related data to an ActiveRecord model from an extjs front-end.

License

Notifications You must be signed in to change notification settings

ungue/nested_attributes_for_extjs

Repository files navigation

nested_attributes_for_extjs

Allow extjs to use NestedAttributes in ActiveRecord models.

This behaviour has been extracted from NestedAttributes module.

As an example:

class Book < ActiveRecord::Base
  has_many :pages
  accepts_nested_attributes_extjs_for :pages
end

book.pages_attributes = attributes

# Where attributes can be
{ 
  "ext-record-1" => {
    "number" => "1",
    ...
  }, 
  "ext-record-2" => {
    "number" => "2",
    ...
  },
  3 => {
    "number" => "30",
  }
}

It means that we are creating 2 new pages for the book (“1” and “2”) and updating the page whose id is 3 to have the number “30”. All the other pages will be removed from the book (This is a very important thing to have in mind).

We can se that keys like “ext-record-…” appears in the hash when a new element is going to be created. That is so because Extjs doesn’t allow arrays in the parameters (well, we could encode the array in a JSON object, but it isn’t the purpose of this plugin).

TODO

  • Clean the code to remove some methods posibly repeated from nested_attributes

  • Tests

About

An easy way to Create/Update/Destroy related data to an ActiveRecord model from an extjs front-end.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages