To get better understanding of how Angular works with Rails I am
creating a simple todo app.This is my first week with Angular and I have
no idea how to use it correctly with rails.
An idea is following. I have a list of todos and when I click on todo I
get a list of tasks below which are associated with this todo list. You
can take a look on attached picture, maybe it will explain better what I
am trying to say here.
DB:
One “todo” has many “tasks”. todo_id is a FK in the task model.
This is what I’ve done to display all todos:
{{todo.title}}
{{task.title}}
As you see so far I get a list of tasks from todo but if I add a task or
delete one I have to reload a todo and I have no idea how to update html
on flight using Angular.
This is how I delete a todo (I hope it is not very ugly
Todo = $resource("/api/todos/:id", {id: “@id”}, {update: {method:
“PUT”}})
$scope.todos = Todo.query()
$scope.deleteTodo = (id) ->
todo = (item for item in $scope.todos when item.id is id)[0]
Todo.remove(todo)
$scope.$apply(removeFromArray($scope.todos, todo))
I would really appreciate if someone could give me a good example of how
Angular lives with Rails and how to use “Angular.resource” correctly.
Meanwhile I will be praying and reading angular sources