-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
376 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
class TodosController < ApplicationController | ||
# GET /todos | ||
# GET /todos.xml | ||
def index | ||
@todos = Todo.all | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json { render :json => @todos } | ||
format.xml { render :xml => @todos } | ||
end | ||
end | ||
|
||
# GET /todos/1 | ||
# GET /todos/1.xml | ||
def show | ||
@todo = Todo.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json { render :json => @todo } | ||
format.xml { render :xml => @todo } | ||
end | ||
end | ||
|
||
# GET /todos/new | ||
# GET /todos/new.xml | ||
def new | ||
@todo = Todo.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.xml { render :xml => @todo } | ||
end | ||
end | ||
|
||
# GET /todos/1/edit | ||
def edit | ||
@todo = Todo.find(params[:id]) | ||
end | ||
|
||
# POST /todos | ||
# POST /todos.xml | ||
def create | ||
@todo = Todo.new(params[:todo]) | ||
|
||
respond_to do |format| | ||
if @todo.save | ||
format.html { redirect_to(@todo, :notice => 'Todo was successfully created.') } | ||
format.json { render :json => @todo, :status => :created, :location => @todo } | ||
format.xml { render :xml => @todo, :status => :created, :location => @todo } | ||
else | ||
format.html { render :action => "new" } | ||
format.json { render :json => @todo.errors, :status => :unprocessable_entity } | ||
format.xml { render :xml => @todo.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /todos/1 | ||
# PUT /todos/1.xml | ||
def update | ||
@todo = Todo.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @todo.update_attributes(params[:todo]) | ||
format.html { redirect_to(@todo, :notice => 'Todo was successfully updated.') } | ||
format.xml { head :ok } | ||
else | ||
format.html { render :action => "edit" } | ||
format.xml { render :xml => @todo.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /todos/1 | ||
# DELETE /todos/1.xml | ||
def destroy | ||
@todo = Todo.find(params[:id]) | ||
@todo.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to(todos_url) } | ||
format.xml { head :ok } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module TodosHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Todo < ActiveRecord::Base | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<%= form_for(@todo) do |f| %> | ||
<% if @todo.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@todo.errors.count, "error") %> prohibited this todo from being saved:</h2> | ||
|
||
<ul> | ||
<% @todo.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= f.label :title %><br /> | ||
<%= f.text_field :title %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :description %><br /> | ||
<%= f.text_area :description %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :priority %><br /> | ||
<%= f.text_field :priority %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :position %><br /> | ||
<%= f.text_field :position %> | ||
</div> | ||
<div class="actions"> | ||
<%= f.submit %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing todo</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Show', @todo %> | | ||
<%= link_to 'Back', todos_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<h1>Listing todos</h1> | ||
|
||
<table> | ||
<tr> | ||
<th>Title</th> | ||
<th>Description</th> | ||
<th>Priority</th> | ||
<th>Position</th> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
|
||
<% @todos.each do |todo| %> | ||
<tr> | ||
<td><%= todo.title %></td> | ||
<td><%= todo.description %></td> | ||
<td><%= todo.priority %></td> | ||
<td><%= todo.position %></td> | ||
<td><%= link_to 'Show', todo %></td> | ||
<td><%= link_to 'Edit', edit_todo_path(todo) %></td> | ||
<td><%= link_to 'Destroy', todo, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New Todo', new_todo_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New todo</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', todos_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<p> | ||
<b>Title:</b> | ||
<%= @todo.title %> | ||
</p> | ||
|
||
<p> | ||
<b>Description:</b> | ||
<%= @todo.description %> | ||
</p> | ||
|
||
<p> | ||
<b>Priority:</b> | ||
<%= @todo.priority %> | ||
</p> | ||
|
||
<p> | ||
<b>Position:</b> | ||
<%= @todo.position %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_todo_path(@todo) %> | | ||
<%= link_to 'Back', todos_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class CreateTodos < ActiveRecord::Migration | ||
def self.up | ||
create_table :todos do |t| | ||
t.string :title | ||
t.text :description | ||
t.integer :priority | ||
t.integer :position | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :todos | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# Note that this schema.rb definition is the authoritative source for your | ||
# database schema. If you need to create the application database on another | ||
# system, you should be using db:schema:load, not running all the migrations | ||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
# you'll amass, the slower it'll run and the greater likelihood for issues). | ||
# | ||
# It's strongly recommended to check this file into your version control system. | ||
|
||
ActiveRecord::Schema.define(:version => 20110315073827) do | ||
|
||
create_table "todos", :force => true do |t| | ||
t.string "title" | ||
t.text "description" | ||
t.integer "priority" | ||
t.integer "position" | ||
t.datetime "created_at" | ||
t.datetime "updated_at" | ||
end | ||
|
||
end |
Oops, something went wrong.