Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: a54cbcda0f
Fetching contributors…

Cannot retrieve contributors at this time

63 lines (45 sloc) 2.348 kB


Allow an ActiveRecord model to output its attributes in JSON, attached to a uniquely identifiable DOM element.


  • Store complex, possibly nested attribute data in the DOM using JSON format for simplicity and performance

  • Attach the data to any DOM element that corresponds to a view of the resource. If that resource is removed via AJAX, the data will be removed with it

  • Retrieve the data and populate forms automatically


As you are writing elements out in a view, i.e. as rows in a table, add resource attributes to an array: (example in HAML)

resources_data = []
  - posts.each do |post|

- resources_data << (resource_data = post.dom_attribute_data) %tr.resource{:id => resorce_data[:dom_id]} %td= %td= post.title %td Select


Now you can capture the data, for example, when the link is clicked in the row.

$(document).delegate('', function(event) {
  var domId = $(this).parents('.resource:first').attr('id');
  var attrs = $('#' + domId).data('dr_data');

Or, populate a properly-tagged DOM target with the values, automatically:

  %span{:data => {:dr_attr => 'post_date'}}
  %input{:data => {:dr_attr => 'post_title'}}

  $(document).delegate('', function(event) {

Contributing to domifiable_resource

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright © 2011 Fullware (Doug Puchalski). See LICENSE.txt for further details.

Jump to Line
Something went wrong with that request. Please try again.