Skip to content

Instantly share code, notes, and snippets.

View digitalplaywright's full-sized avatar

Andreas Sæbjørnsen digitalplaywright

View GitHub Profile
@digitalplaywright
digitalplaywright / application.js
Created December 26, 2014 20:14
Start of Ember ActiveModel Serializer support for accepts_nested_attributes_for with deletion
//file app/serializers/application.js
import DS from "ember-data";
import Ember from "ember";
export default DS.ActiveModelSerializer.extend({
serializeHasMany: function (record, json, relationship) {
var key = relationship.key;
var hasManyRecords = Ember.get(record, key);
var Post = DS.Model.extend({
title: DS.attr('string'),
details: DS.attr('string'),
user: DS.belongsTo('user')
});
export default Post;
Handlebars.registerHelper("ifData", function(property, fn)
{
var context = (fn.contexts && fn.contexts[0]) || this;
var args = [property];
var canAction = function(can_args)
{
alert('I was called for '+can_args[0].get('id'));
return true;
};
Handlebars.registerHelper("can", function(actor, action, object, fn)
{
var context = (fn.contexts && fn.contexts[0]) || this;
var canAction = function(can_args)
{
var rules = context.container.lookup('rules:eval');
return rules.can({activity: can_args[1], actor: can_args[0], object: can_args[2] });
Handlebars.registerHelper('can', function(permissionName, options){
var rules = this.container.lookup('rules:eval');
if ( options == null ){
options = { activity: permissionName };
}else{
options['activity'] = permissionName;
}
@digitalplaywright
digitalplaywright / .gitignore
Created May 7, 2012 02:57 — forked from karmi/.gitignore
Bootstrap, install and configure ElasticSearch with Chef Solo
.DS_Store
node.json
tmp/
@digitalplaywright
digitalplaywright / gist:1535744
Created December 29, 2011 19:21
Updated examples with the suggested MongoMapper :inverse_of syntax

We use inverse_of in three ways in Mongoid. I've attempted to translate the way we currently use inverse_of in Mongoid to the @bkeepers inverse_of syntax:

  1. Update: use :class_name to specify the class and :inverse_of to specify the inverse association if the :class_name and :inverse_of association can not be inferred from the association definition.

To declare multiple associations to the same model.

I believe :inverse_of and :class_name can be inferred in the trivial case where the field name equals the class or collection name.

@digitalplaywright
digitalplaywright / gist:1535543
Created December 29, 2011 18:46
Mongoid syntax for inverse_of relations
  1. To declare multiple fields using the same embedded model, like e.g:
class Profile
  include Mongoid::Document

  embeds_many :i_am_a,    :class_name => "TagInteraction", :inverse_of => :i_am_a
  embeds_many :i_love_to, :class_name => "TagInteraction", :inverse_of => :i_love_to
end
@digitalplaywright
digitalplaywright / gist:1533662
Created December 29, 2011 11:36
Updated use-cases for the inverse of "many :in"

We use inverse_of in three ways in Mongoid. I've attempted to translate the way we currently use inverse_of in Mongoid to the @bkeepers inverse_of syntax:

  1. Update: use :class_name to specify the class and :inverse_of to specify the inverse association if the :class_name and :inverse_of association can not be inferred from the association definition.

To declare multiple associations to the same model.

I believe :inverse_of and :class_name can be inferred in the trivial case where the field name equals the class or collection name.