Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 4 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 03, 2011
Chad Pytel show, delete bef8679
Chad Pytel remove logging 378ca05
Chad Pytel minor styling 518b6bf
Chad Pytel *.swo 3a5d9c0
View
1 .gitignore
@@ -1 +1,2 @@
*.swp
+*.swo
View
BIN public/javascripts/.application.js.swo
Binary file not shown.
View
37 public/javascripts/application.js
@@ -11,5 +11,40 @@ $(function() {
return false;
});
- $(".tasks ul a")
+ $(".tasks li a").live("click", function(event) {
+ event.preventDefault();
+ event.stopPropagation();
+
+ $.get($(this).prop('href'), null, function(data) {
+ $(".index").hide().after(data);
+ });
+
+ return false;
+ });
+
+ $("a.back").live("click", function(event) {
+ event.preventDefault();
+ event.stopPropagation();
+
+ $(".task").remove();
+ $(".index").show();
+
+ return false;
+ });
+
+ $("a.delete").live("click", function(event) {
+ event.preventDefault();
+ event.stopPropagation();
+
+ $.ajax($(this).prop('href'), {
+ data: { "_method": "DELETE" },
+ success: function(data) {
+ $(".task").remove();
+ $(".index").show();
+ },
+ type: "POST"
+ });
+
+ return false;
+ });
});
View
17 public/stylesheets/application.css
@@ -5,3 +5,20 @@ body {
.users li {
}
+
+.task {
+ width: 500px;
+}
+
+a.back {
+ color: black;
+}
+
+a.delete {
+ color: red;
+ float: right;
+}
+
+h1 {
+ margin-top: 15px;
+}
View
20 server.rb
@@ -2,6 +2,7 @@
require 'sinatra'
configure do
+ set :method_override, true
set :tasks, [
{ 'id' => 1, 'title' => "Get Passport" },
{ 'id' => 2, 'title' => "Book tickets" },
@@ -11,13 +12,26 @@
end
get '/' do
- p settings.tasks
erb :index, :locals => { :tasks => settings.tasks }
end
-post '/tasks.json' do
+post '/tasks' do
params['id'] = rand(10000);
settings.tasks << params
- p settings.tasks
"<li><a href='/tasks/#{params['id']}'>#{params['title']}</a></li>"
end
+
+get "/tasks/:id" do
+ erb :show, :locals => { :task => find_task(params[:id]) }, :layout => false
+end
+
+delete "/tasks/:id" do
+ settings.tasks.reject! { |task| task["id"] == params[:id].to_i }
+ ""
+end
+
+helpers do
+ def find_task(id)
+ settings.tasks.find { |task| task["id"] == id.to_i }
+ end
+end
View
2 views/index.erb
@@ -7,7 +7,7 @@
<% end %>
</ul>
- <form id="new_task" action="tasks.json">
+ <form id="new_task" action="/tasks">
<ol class="inputs">
<li>
<label for="title_input">Title</label>
View
6 views/show.erb
@@ -0,0 +1,6 @@
+<div id="task_<%= task["id"] %>" class="task">
+ <a href="#" class="back">&laquo; Back</a>
+ <a href="/tasks/<%= task["id"] %>" class="delete">Delete</a>
+
+ <h1><%= task["title"] %></h1>
+</div>

No commit comments for this range

Something went wrong with that request. Please try again.