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 GET "/admin/tasks/completed?id=4" for 127.0.0.1 at 2012-04-27 11:18:23 +0200
Processing by Admin::TasksController#show as /
Parameters: {"id"=>"completed"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Task Load (0.1ms) SELECT "tasks".* FROM "tasks" WHERE "tasks"."id" = ? LIMIT 1 [["id", "completed"]]
Completed 500 Internal Server Error in 2ms

ActiveRecord::RecordNotFound (Couldn't find Task with id=completed):
app/controllers/admin/tasks_controller.rb:17:in `show'

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.0ms)

@Znow
Copy link
Author

Znow commented Apr 27, 2012

Started GET "/admin/tasks/completed?id=4" for 127.0.0.1 at 2012-04-27 11:30:08 +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:0x007fa7915c6878>): 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.9ms)
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.3ms)

@Znow
Copy link
Author

Znow commented Apr 27, 2012

Started POST "/admin/tasks/completed" for 127.0.0.1 at 2012-04-27 11:38:35 +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.1ms) SELECT "tasks".* FROM "tasks" WHERE "tasks"."id" = ? LIMIT 1 [["id", "4"]]
Completed 500 Internal Server Error in 2ms

NoMethodError (undefined method complete?' for #<Task:0x007fa795ba9ed0>): 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 (27.5ms)
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.9ms)
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 (34.6ms)

@Znow
Copy link
Author

Znow commented Apr 27, 2012

Started POST "/admin/tasks/completed" for 127.0.0.1 at 2012-04-27 11:40:48 +0200

ActionController::RoutingError (No route matches [POST] "/admin/tasks/completed"):
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in call' actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:incall'
railties (3.2.3) lib/rails/rack/logger.rb:26:in call_app' railties (3.2.3) lib/rails/rack/logger.rb:16:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in call' rack (1.4.1) lib/rack/methodoverride.rb:21:incall'
rack (1.4.1) lib/rack/runtime.rb:17:in call' activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:incall'
rack (1.4.1) lib/rack/lock.rb:15:in call' actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:incall'
railties (3.2.3) lib/rails/engine.rb:479:in call' railties (3.2.3) lib/rails/application.rb:220:incall'
rack (1.4.1) lib/rack/content_length.rb:14:in call' railties (3.2.3) lib/rails/rack/log_tailer.rb:14:incall'
thin (1.3.1) lib/thin/connection.rb:80:in block in pre_process' thin (1.3.1) lib/thin/connection.rb:78:incatch'
thin (1.3.1) lib/thin/connection.rb:78:in pre_process' thin (1.3.1) lib/thin/connection.rb:53:inprocess'
thin (1.3.1) lib/thin/connection.rb:38:in receive_data' eventmachine (0.12.10) lib/eventmachine.rb:256:inrun_machine'
eventmachine (0.12.10) lib/eventmachine.rb:256:in run' thin (1.3.1) lib/thin/backends/base.rb:61:instart'
thin (1.3.1) lib/thin/server.rb:159:in start' rack (1.4.1) lib/rack/handler/thin.rb:13:inrun'
rack (1.4.1) lib/rack/server.rb:265:in start' railties (3.2.3) lib/rails/commands/server.rb:70:instart'
railties (3.2.3) lib/rails/commands.rb:55:in block in <top (required)>' railties (3.2.3) lib/rails/commands.rb:50:intap'
railties (3.2.3) lib/rails/commands.rb:50:in <top (required)>' script/rails:6:inrequire'
script/rails:6:in `

'

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/routing_error.erb within rescues/layout (0.5ms)

@mjtko
Copy link

mjtko commented Apr 27, 2012

$(".completed").live("change", function(e) {
    var url = '/admin/tasks/' + this.value + '/completed';
    $.ajax({
      type: 'POST',
      url: url,
      data: '', 
      beforeSend: function() { console.log(this,e) },
      success: function() { alert('All done.') }
    });
  });

@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