Skip to content

Instantly share code, notes, and snippets.

Created February 23, 2017 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c9163cade0ba50450b18c94022bb8146 to your computer and use it in GitHub Desktop.
Save anonymous/c9163cade0ba50450b18c94022bb8146 to your computer and use it in GitHub Desktop.
angular.module('mymodule').controller "ItemNewCtrl", ['$scope', '$modal', '$http', 'current_session', ($scope, $modal, $http, current_session)->
$scope.item = current_session.item
$scope.submitItem = (data, redirect_url) ->
$http.post("/new_item_url", data).success(
(send_response)->
window.location.href = redirect_url
).error(
(r)->
Flashing.setMessage("bad","Error." )
)
$scope.create = (item)->
data = { item: item }
# CREATING A NEW item
$scope.submitItem(data, "/redirect_url")
]
<div ng-controller="ItemNewCtrl">
<form ng-submit="create(item);" ng-init="item = <%= @item.to_json %>">
<textarea id="item_description" ng-model="item.description"><%= @item[:description] %></textarea>
<input type="hidden" ng-model="item.attribute">
<button type="submit">Submit</button>
</form>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment