Skip to content

Instantly share code, notes, and snippets.

@daniel-nelson
Created January 22, 2014 03:38
Show Gist options
  • Save daniel-nelson/8553122 to your computer and use it in GitHub Desktop.
Save daniel-nelson/8553122 to your computer and use it in GitHub Desktop.
var ingredients, recipeModule, recipes;
recipeModule = angular.module('recipeModule', ['ngResource']);
recipeModule.config([
'$httpProvider', function($httpProvider) {
var token;
$httpProvider.defaults.headers['common']['Accept'] = 'application/json';
token = $("meta[name='csrf-token']").attr('content');
return $httpProvider.defaults.headers['common']['X-CSRF-Token'] = token;
}
]);
recipes = function($resource) {
return $resource('/recipes/:id', {}, {
index: {
method: 'GET',
isArray: true
},
show: {
method: 'GET'
},
create: {
method: 'POST'
},
update: {
method: 'PUT'
},
destroy: {
method: 'DELETE'
}
});
};
recipeModule.factory('Recipe', ['$resource', recipes]);
ingredients = function($resource) {
return $resource('/ingredients/:id', {}, {
index: {
method: 'GET',
isArray: true
},
show: {
method: 'GET'
},
create: {
method: 'POST'
},
update: {
method: 'PUT'
},
destroy: {
method: 'DELETE'
}
});
};
recipeModule.factory('Ingredient', ['$resource', ingredients]);
recipeModule.directive('suggestIngredient', function() {
return {
link: function(scope, el, attrs) {
return setTimeout(function() {
return el.typeahead({
source: scope.existing_ingredients,
mode: 'multiple'
});
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment