I follow http://railscasts.com/episodes/136-jquery-ajax-revised?view=comments to complete the ajax on Rails course. but I totally confused.
in the controller, it fetch two kinds of task.
controllers/tasks_controller.rb
4: @incomplete_tasks = Task.where(complete: false)
5: @complete_tasks = Task.where(complete: true)
and render it in index.html.erb by
views/tasks/index.html.erb
6:<div class="tasks" id="incomplete_tasks">
7: <%= render @incomplete_tasks %>
11:<div class="tasks" id="complete_tasks">
12: <%= render @complete_tasks %>
also you can append a new task by
views/tasks/create.js.erb
3:$('#incomplete_tasks').append('<%= j render(@task) %>');
however , there is no _incomplete_task.html.erb and _complete_task.html.erb , so how could rails know what to render.
it confuse me totally. please give me some directions, thanks~
[tasks] $ ls
_form.html.erb* create.js.erb* index.html.erb* new.js.erb*
_task.html.erb* destroy.js.erb* new.html.erb* update.js.erb*
Try using the partials explicitly:
views/tasks/index.html.erb
6:<div class="tasks" id="incomplete_tasks">
7: <%= render partial: 'task', collection: @incomplete_tasks %>
11:<div class="tasks" id="complete_tasks">
12: <%= render partial: 'task', collection: @complete_tasks %>
and
views/tasks/create.js.erb
3:$('#incomplete_tasks').append('<%= j render(partial: 'task', object: @task) %>');