Permalink
Browse files

after first day

  • Loading branch information...
1 parent 669948f commit bad9929b3858b0d26656f62dbde718b2e986ae60 Jason Draper committed Jun 22, 2012
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+// Place all the styles related to the Lists controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,56 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px; }
+
+a {
+ color: #000;
+ &:visited {
+ color: #666; }
+ &:hover {
+ color: #fff;
+ background-color: #000; } }
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px; } }
+
+#notice {
+ color: green; }
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table; }
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff; }
+ ul li {
+ font-size: 12px;
+ list-style: square; } }
@@ -0,0 +1,83 @@
+class ListsController < ApplicationController
+ # GET /lists
+ # GET /lists.json
+ def index
+ @lists = List.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @lists }
+ end
+ end
+
+ # GET /lists/1
+ # GET /lists/1.json
+ def show
+ @list = List.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @list }
+ end
+ end
+
+ # GET /lists/new
+ # GET /lists/new.json
+ def new
+ @list = List.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @list }
+ end
+ end
+
+ # GET /lists/1/edit
+ def edit
+ @list = List.find(params[:id])
+ end
+
+ # POST /lists
+ # POST /lists.json
+ def create
+ @list = List.new(params[:list])
+
+ respond_to do |format|
+ if @list.save
+ format.html { redirect_to @list, notice: 'List was successfully created.' }
+ format.json { render json: @list, status: :created, location: @list }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @list.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /lists/1
+ # PUT /lists/1.json
+ def update
+ @list = List.find(params[:id])
+
+ respond_to do |format|
+ if @list.update_attributes(params[:list])
+ format.html { redirect_to @list, notice: 'List was successfully updated.' }
+ format.json { head :ok }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @list.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /lists/1
+ # DELETE /lists/1.json
+ def destroy
+ @list = List.find(params[:id])
+ @list.destroy
+
+ respond_to do |format|
+ format.html { redirect_to lists_url }
+ format.json { head :ok }
+ end
+ end
+end
@@ -0,0 +1,2 @@
+module ListsHelper
+end
View
@@ -0,0 +1,4 @@
+class List < ActiveRecord::Base
+ attr_accessible :name, :description
+ has_many :tasks
+end
View
@@ -1,5 +1,7 @@
class Task < ActiveRecord::Base
- attr_accessible :name, :due_at
+ belongs_to :list
+
+ attr_accessible :name, :due_at, :list_id
validates :name, presence: true
scope :complete, where(:completed => true)
@@ -0,0 +1,25 @@
+<%= form_for(@list) do |f| %>
+ <% if @list.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@list.errors.count, "error") %> prohibited this list from being saved:</h2>
+
+ <ul>
+ <% @list.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :description %><br />
+ <%= f.text_area :description %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing list</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @list %> |
+<%= link_to 'Back', lists_path %>
@@ -0,0 +1,25 @@
+<h1>Listing lists</h1>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Description</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @lists.each do |list| %>
+ <tr>
+ <td><%= list.name %></td>
+ <td><%= list.description %></td>
+ <td><%= link_to 'Show', list %></td>
+ <td><%= link_to 'Edit', edit_list_path(list) %></td>
+ <td><%= link_to 'Destroy', list, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New List', new_list_path %>
@@ -0,0 +1,5 @@
+<h1>New list</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', lists_path %>
@@ -0,0 +1,15 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Name:</b>
+ <%= @list.name %>
+</p>
+
+<p>
+ <b>Description:</b>
+ <%= @list.description %>
+</p>
+
+
+<%= link_to 'Edit', edit_list_path(@list) %> |
+<%= link_to 'Back', lists_path %>
@@ -6,7 +6,7 @@
<%= form_for @task do |form| %>
- <%= form.text_field :name %>
- <%= form.datetime_select :due_at %>
+ <div>Name: <%= form.text_field :name %></div>
+ <div>Due Date: <%= form.datetime_select :due_at %></div>
<%= form.submit %>
<% end %>
View
@@ -1,4 +1,6 @@
Todo::Application.routes.draw do
+ resources :lists
+
resources :tasks
resources :completed_tasks, only: [:create]
# The priority is based upon order of creation:
@@ -0,0 +1,24 @@
+class CreateLists < ActiveRecord::Migration
+ def up
+ create_table :lists do |t|
+ t.string :name
+ t.text :description
+
+ t.timestamps
+ end
+
+ add_column :tasks, :list_id, :integer
+
+ Task.reset_column_information
+ inbox = List.create(:name => "Inbox")
+ Task.all.each do |task|
+ task.list_id = inbox.id
+ task.save
+ end
+ end
+
+ def down
+ remove_column :tasks, :list_id
+ drop_table :lists
+ end
+end
View
@@ -11,14 +11,22 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120621184304) do
+ActiveRecord::Schema.define(:version => 20120622131219) do
+
+ create_table "lists", :force => true do |t|
+ t.string "name"
+ t.text "description"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
create_table "tasks", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "due_at"
t.boolean "completed", :default => false
+ t.integer "list_id"
end
end
View
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+ description: MyText
+
+two:
+ name: MyString
+ description: MyText
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class ListsControllerTest < ActionController::TestCase
+ setup do
+ @list = lists(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:lists)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create list" do
+ assert_difference('List.count') do
+ post :create, list: @list.attributes
+ end
+
+ assert_redirected_to list_path(assigns(:list))
+ end
+
+ test "should show list" do
+ get :show, id: @list.to_param
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @list.to_param
+ assert_response :success
+ end
+
+ test "should update list" do
+ put :update, id: @list.to_param, list: @list.attributes
+ assert_redirected_to list_path(assigns(:list))
+ end
+
+ test "should destroy list" do
+ assert_difference('List.count', -1) do
+ delete :destroy, id: @list.to_param
+ end
+
+ assert_redirected_to lists_path
+ end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ListsHelperTest < ActionView::TestCase
+end
View
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ListTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit bad9929

Please sign in to comment.