Class: Bowline::Binders::Collection

Inherits:
Base show all
Defined in:
lib/bowline/binders/collection.rb

Instance Attribute Summary

Attributes inherited from Base

#item

Class Method Summary collapse

Methods inherited from Base

bowline, callback, callback_proc, callback_proc=, created, destroyed, find, initial, #initialize, instance_invoke, items=, jquery, js_invoke, klass, logger, page, populate, setup, updated, windows

Methods included from Watcher::Base

extended, included, #watcher

Methods included from Desktop::Bridge::ClassMethods

#js_expose

Constructor Details

This class inherits a constructor from Bowline::Binders::Base

Class Method Details

.bind(klass) ⇒ Object

Associate the binder with a model to setup callbacks so changes to the model are automatically reflected in the view. Example:

bind Post

When the bound class is created/updated/deleted the binder’s callbacks are executed and the view updated accordingly.

Classes inheriting from ActiveRecord and SuperModel are automatically compatible, but if you’re using your own custom model you need to make sure it responds to the following methods:

* all                    - return all records
* find(id)               - find record by id
* after_create(method)   - after_create callback
* after_update(method)   - after_update callback
* after_destroy(method)  - after_destroy callback

The klass’ instance needs to respond to:

* id      - returns record id
* to_js   - return record's attribute hash

You can override the to_js method on the model instance in order to return specific attributes for the view.



29
30
31
32
33
# File 'lib/bowline/binders/collection.rb', line 29

def bind(klass)
  @klass = klass
  observer = Observer.new(self)
  @klass.add_observer(observer)
end