Skip to content
/ sheepit Public

clone of the sheepit jquery plugin with extra callback that helps with accepts_nested_attributes_for in rails

License

Notifications You must be signed in to change notification settings

bxjx/sheepit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Clone of the jquery plugin sheepit that is hosted at google code.

A post-removal callback has been added. This is useful for use with accepts_nested_attributes_for :items, :allow_destroy => true in rails, so that :_destroy => '1' can be set. Note: the parameter used to mark for destroy is delete in rails 2.3 and destroy in 3.

If there's any interest in this, message me and I could maybe make rails helpers.

Here's an example:

$('#sheepItForm').livequery(function(){
  $(this).sheepIt({
    afterRemove: function(index, formToRemove){
      // parse the removed form to extract rails Active Record item id. You'll 
      // need to add this class to your hidden input that has the id.
      var item_id = formToRemove.find('input.avatar_id').val();
      if (item_id){
        $('#sheepItForm_noforms_template').append(
          '<input type="hidden" name="member[avatars_attributes][][id]" value="' + item_id + '" />' +
          '<input type="hidden" name="member[avatars_attributes][][_destroy]" value="1" />'
        );
      }
    },
    data: avatars
  });
});

I then also put:

:javascript
  var avatars = #{@member.avatars.to_json(:only => [:id, :name])};

into my view (this is haml) so that the form is populated with has many items.

About

clone of the sheepit jquery plugin with extra callback that helps with accepts_nested_attributes_for in rails

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published