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:
<div data-ng-repeat="todo in todos" class="row todo" >
    <h2 class="col-xs-10" ng-click="changeVisibleState(todo.id)">
        {{todo.title}}
    </h2>
     <i ng-click="deleteTodo(todo.id)" class="glyphicon glyphicon-trash
col-xs-2"/>
     <div class="col-md-6 col-md-offset-2" ng-if="visible(todo.id)">
        <div data-ng-repeat="task in todo.tasks" id="tasks"
class="task">
            <h3 class="col-xs-10">{{task.title}}</h3>
            <i class="glyphicon glyphicon-trash"
ng-click="deleteTask(task.id, todo.id)"/>
        </div>
      <-- form -->
      </div>
</div>

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 :)

Attachments:
http://www.ruby-forum.com/attachment/10800/tasks.png


-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/d07ac35a74cbaf459b3dac07e6d085a5%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to