Commit a92e9e3

mo khan <mo@mokhan.ca>
2013-06-23 02:08:28
add neighborhoods
1 parent 9b8ae79
app/assets/javascripts/neighbourhoods.js.coffee
@@ -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/
app/assets/stylesheets/neighbourhoods.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Neighbourhoods controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
app/controllers/neighbourhoods_controller.rb
@@ -0,0 +1,5 @@
+class NeighbourhoodsController < ApplicationController
+  def index
+    @neighbourhoods = Neighbourhood.all
+  end
+end
app/helpers/neighbourhoods_helper.rb
@@ -0,0 +1,2 @@
+module NeighbourhoodsHelper
+end
app/models/neighbourhood.rb
@@ -0,0 +1,3 @@
+class Neighbourhood < ActiveRecord::Base
+  attr_accessible :name, :status
+end
app/views/layouts/_header.html.erb
@@ -9,6 +9,7 @@
       <a class="brand" href="/">Rebuild YYC</a>
       <div class="nav-collapse">
         <ul class="nav">
+          <li><%= link_to "Neighbourhoods", neighbourhoods_path %></li>
           <li><a href="http://t.co/exF4flyIPd" target="_blank">Map</a></li>
         </ul>
         <ul class="nav pull-right">
app/views/neighbourhoods/index.html.erb
@@ -0,0 +1,25 @@
+<h1>Listing neighbourhoods</h1>
+
+<table>
+  <tr>
+    <th>Name</th>
+    <th>Status</th>
+    <th></th>
+    <th></th>
+    <th></th>
+  </tr>
+
+<% @neighbourhoods.each do |neighbourhood| %>
+  <tr>
+    <td><%= neighbourhood.name %></td>
+    <td><%= neighbourhood.status %></td>
+    <td><%= link_to 'Show', neighbourhood %></td>
+    <td><%= link_to 'Edit', edit_neighbourhood_path(neighbourhood) %></td>
+    <td><%= link_to 'Destroy', neighbourhood, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+  </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Neighbourhood', new_neighbourhood_path %>
config/routes.rb
@@ -2,5 +2,6 @@ Yycrebuild::Application.routes.draw do
   devise_for :users
 
   resources :needs
+  resources :neighbourhoods
   root :to => 'needs#index'
 end
db/migrate/20130623015151_create_neighbourhoods.rb
@@ -0,0 +1,10 @@
+class CreateNeighbourhoods < ActiveRecord::Migration
+  def change
+    create_table :neighbourhoods do |t|
+      t.string :name
+      t.string :status
+
+      t.timestamps
+    end
+  end
+end
db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20130622175108) do
+ActiveRecord::Schema.define(:version => 20130623015151) do
 
   create_table "needs", :force => true do |t|
     t.text     "description"
@@ -20,6 +20,13 @@ ActiveRecord::Schema.define(:version => 20130622175108) do
     t.datetime "updated_at",  :null => false
   end
 
+  create_table "neighbourhoods", :force => true do |t|
+    t.string   "name"
+    t.string   "status"
+    t.datetime "created_at", :null => false
+    t.datetime "updated_at", :null => false
+  end
+
   create_table "taggings", :force => true do |t|
     t.integer  "tag_id"
     t.integer  "taggable_id"
spec/controllers/neighbourhoods_controller_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe NeighbourhoodsController do
+  describe :index do
+    it "should load each neighbourhood" do
+      neighbourhood = Neighbourhood.create!(:name => 'sunnyside', :status => "red")
+      get :index
+      assigns(:neighbourhoods).should include(neighbourhood)
+    end
+  end
+end
spec/models/neighbourhood_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe Neighbourhood do
+  describe :attributes do
+    subject { Neighbourhood.new }
+    it { should respond_to :name }
+    it { should respond_to :status }
+  end
+end
spec/requests/neighbourhoods_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe "Neighbourhoods" do
+  describe "GET /neighbourhoods" do
+    it "should connect to the index page" do
+      get neighbourhoods_path
+      response.status.should be(200)
+    end
+  end
+end
spec/routing/neighbourhoods_routing_spec.rb
@@ -0,0 +1,10 @@
+require "spec_helper"
+
+describe NeighbourhoodsController do
+  describe "routing" do
+
+    it "routes to #index" do
+      get("/neighbourhoods").should route_to("neighbourhoods#index")
+    end
+  end
+end