Skip to content

Instantly share code, notes, and snippets.

@Znow
Created April 27, 2012 09:06
Show Gist options
  • Save Znow/2507660 to your computer and use it in GitHub Desktop.
Save Znow/2507660 to your computer and use it in GitHub Desktop.
<% content_for :modal_partials do %>
<%= render :partial => "/admin/tasks/edit_task_modal", :locals => {:task => t} %>
<%= render :partial => "/admin/tasks/delete_task_modal", :locals => {:task => t} %>
<% end %>
<%# content_for :pre_body_close do
<script>
alert('hej')
$(".completed").live("change", function(el) {
$.ajax({
url: "/admin/tasks/completed",
beforeSend: function() { alert("Hi"+el) },
data: "id="+el,
success: function() { alert('Bye') }
});
});
</script>
end %>
<tr>
<td>
<%= check_box_tag "completed", t.id, t.completed, :class => "completed" %>
</td>
<td><%= t.task_type %></td>
<td><%= link_to "#{truncate(t.subject, :length => 20)}", admin_task_path(t) %></td>
<td><%= t.responsible(&:name) %></td>
<td><%= link_to t.client, admin_client_path(t.client) unless t.client.nil? %></td>
<td><%= t.deadline.strftime("%d/%m/%y %H:%M") %></td>
<td><%= t.author(&:name) %></td>
<td>
<a data-toggle="modal" href="#editTask<%= t.id %>"><%= image_tag "edit.png" %></a>
<a data-toggle="modal" href="#deleteTask<%= t.id %>"><%= image_tag "delete.png" %></a>
</td>
</tr>
$(".completed").live("change", function(e) {
var data = "id=" + this.value;
var url = '/admin/tasks/completed' // + (this.checked ? 'completed' : 'uncompleted');
$.ajax({
type: 'POST',
url: url,
data: data,
beforeSend: function() { console.log(this,e) },
success: function() { alert('All done.') }
});
});
resources "tasks" do
collection do
post 'completed'
end
end
def completed
@task = Task.find(params[:id])
@task.toggle! :complete
render :nothing => true
#if @task.completed != true
#@task.completed = true
#@task.update_attributes :completed, true
#else
#@task.completed = false
#@task.update_attributes :completed, false
#end
#@task.save
end
@Znow
Copy link
Author

Znow commented Apr 27, 2012

Started POST "/admin/tasks/4/completed" for 127.0.0.1 at 2012-04-27 11:46:55 +0200
Processing by Admin::TasksController#completed as /
Parameters: {"id"=>"4"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Task Load (0.2ms) SELECT "tasks".* FROM "tasks" WHERE "tasks"."id" = ? LIMIT 1 [["id", "4"]]
Completed 500 Internal Server Error in 3ms

NoMethodError (undefined method complete?' for #<Task:0x007fe5e7dc1cc8>): app/controllers/admin/tasks_controller.rb:71:incompleted'

Rendered /Users/znowm4n/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.2ms)
Rendered /Users/znowm4n/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms)
Rendered /Users/znowm4n/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (9.1ms)

@Znow
Copy link
Author

Znow commented Apr 27, 2012

Started POST "/admin/tasks/4/completed" for 127.0.0.1 at 2012-04-27 11:46:55 +0200
Processing by Admin::TasksController#completed as /
Parameters: {"id"=>"4"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Task Load (0.2ms) SELECT "tasks".* FROM "tasks" WHERE "tasks"."id" = ? LIMIT 1 [["id", "4"]]
Completed 500 Internal Server Error in 3ms

NoMethodError (undefined method complete?' for #<Task:0x007fe5e7dc1cc8>): app/controllers/admin/tasks_controller.rb:71:incompleted'

Rendered /Users/znowm4n/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.2ms)
Rendered /Users/znowm4n/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms)
Rendered /Users/znowm4n/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (9.1ms)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment