Permalink
Browse files

adding stations

  • Loading branch information...
1 parent 6c7ca73 commit aa45ad4d40a6033eaa6730d987b1fb7d0acaae94 @ajb committed Jul 21, 2012
View
@@ -1,6 +1,7 @@
source 'https://rubygems.org'
gem 'rails', '3.2.6'
+gem 'geocoder'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
View
@@ -40,6 +40,7 @@ GEM
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
+ geocoder (1.1.2)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.4)
@@ -104,6 +105,7 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.2.1)
+ geocoder
jquery-rails
rails (= 3.2.6)
sass-rails (~> 3.2.3)
@@ -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,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,3 @@
+// Place all the styles related to the Stations controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,83 @@
+class StationsController < ApplicationController
+ # GET /stations
+ # GET /stations.json
+ def index
+ @stations = Station.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @stations }
+ end
+ end
+
+ # GET /stations/1
+ # GET /stations/1.json
+ def show
+ @station = Station.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @station }
+ end
+ end
+
+ # GET /stations/new
+ # GET /stations/new.json
+ def new
+ @station = Station.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @station }
+ end
+ end
+
+ # GET /stations/1/edit
+ def edit
+ @station = Station.find(params[:id])
+ end
+
+ # POST /stations
+ # POST /stations.json
+ def create
+ @station = Station.new(params[:station])
+
+ respond_to do |format|
+ if @station.save
+ format.html { redirect_to @station, notice: 'Station was successfully created.' }
+ format.json { render json: @station, status: :created, location: @station }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @station.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /stations/1
+ # PUT /stations/1.json
+ def update
+ @station = Station.find(params[:id])
+
+ respond_to do |format|
+ if @station.update_attributes(params[:station])
+ format.html { redirect_to @station, notice: 'Station was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @station.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /stations/1
+ # DELETE /stations/1.json
+ def destroy
+ @station = Station.find(params[:id])
+ @station.destroy
+
+ respond_to do |format|
+ format.html { redirect_to stations_url }
+ format.json { head :no_content }
+ end
+ end
+end
@@ -0,0 +1,2 @@
+module StationsHelper
+end
@@ -0,0 +1,6 @@
+class Station < ActiveRecord::Base
+ attr_accessible :address, :description, :latitude, :longitude, :name, :station_type
+
+ geocoded_by :address
+ after_validation :geocode
+end
@@ -0,0 +1,41 @@
+<%= form_for(@station) do |f| %>
+ <% if @station.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@station.errors.count, "error") %> prohibited this station from being saved:</h2>
+
+ <ul>
+ <% @station.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :station_type %><br />
+ <%= f.text_field :station_type %>
+ </div>
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :address %><br />
+ <%= f.text_field :address %>
+ </div>
+ <div class="field">
+ <%= f.label :latitude %><br />
+ <%= f.text_field :latitude %>
+ </div>
+ <div class="field">
+ <%= f.label :longitude %><br />
+ <%= f.text_field :longitude %>
+ </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 station</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @station %> |
+<%= link_to 'Back', stations_path %>
@@ -0,0 +1,33 @@
+<h1>Listing stations</h1>
+
+<table>
+ <tr>
+ <th>Station type</th>
+ <th>Name</th>
+ <th>Address</th>
+ <th>Latitude</th>
+ <th>Longitude</th>
+ <th>Description</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @stations.each do |station| %>
+ <tr>
+ <td><%= station.station_type %></td>
+ <td><%= station.name %></td>
+ <td><%= station.address %></td>
+ <td><%= station.latitude %></td>
+ <td><%= station.longitude %></td>
+ <td><%= station.description %></td>
+ <td><%= link_to 'Show', station %></td>
+ <td><%= link_to 'Edit', edit_station_path(station) %></td>
+ <td><%= link_to 'Destroy', station, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Station', new_station_path %>
@@ -0,0 +1,5 @@
+<h1>New station</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', stations_path %>
@@ -0,0 +1,35 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Station type:</b>
+ <%= @station.station_type %>
+</p>
+
+<p>
+ <b>Name:</b>
+ <%= @station.name %>
+</p>
+
+<p>
+ <b>Address:</b>
+ <%= @station.address %>
+</p>
+
+<p>
+ <b>Latitude:</b>
+ <%= @station.latitude %>
+</p>
+
+<p>
+ <b>Longitude:</b>
+ <%= @station.longitude %>
+</p>
+
+<p>
+ <b>Description:</b>
+ <%= @station.description %>
+</p>
+
+
+<%= link_to 'Edit', edit_station_path(@station) %> |
+<%= link_to 'Back', stations_path %>
View
@@ -1,4 +1,6 @@
OaklandPumpsItUp::Application.routes.draw do
+ resources :stations
+
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -0,0 +1,14 @@
+class CreateStations < ActiveRecord::Migration
+ def change
+ create_table :stations do |t|
+ t.string :station_type
+ t.string :name
+ t.string :address
+ t.float :latitude
+ t.float :longitude
+ t.text :description
+
+ t.timestamps
+ end
+ end
+end
View
@@ -0,0 +1,27 @@
+# encoding: UTF-8
+# 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 => 20120721192615) do
+
+ create_table "stations", :force => true do |t|
+ t.string "station_type"
+ t.string "name"
+ t.string "address"
+ t.float "latitude"
+ t.float "longitude"
+ t.text "description"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+end
View
@@ -5,3 +5,8 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
+
+Station.create(station_type: "Citizen Sponsored",
+ name: "Adam's Rad Bike Pump",
+ address: "1023 62nd St. Oakland, CA",
+ description: "I have a bike pump outside by the mailbox.")
@@ -0,0 +1,17 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ station_type: MyString
+ name: MyString
+ address: MyString
+ latitude: 1.5
+ longitude: 1.5
+ description: MyText
+
+two:
+ station_type: MyString
+ name: MyString
+ address: MyString
+ latitude: 1.5
+ longitude: 1.5
+ description: MyText
Oops, something went wrong.

0 comments on commit aa45ad4

Please sign in to comment.