Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Interim commit, while setting up app for proper REST config

  • Loading branch information...
commit d771cdb7b6213fb5fce216d8164bef0ddce5287a 1 parent 46e9640
@aspittal authored
View
2  app/assets/javascripts/index.js.coffee → app/assets/javascripts/accidents.js.coffee
@@ -1,3 +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/
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/d
View
3  app/assets/stylesheets/accidents.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Accidents controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
56 app/assets/stylesheets/scaffolds.css.scss
@@ -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; } }
View
83 app/controllers/accidents_controller.rb
@@ -0,0 +1,83 @@
+class AccidentsController < ApplicationController
+ # GET /accidents
+ # GET /accidents.json
+ def index
+ @accidents = Accident.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @accidents }
+ end
+ end
+
+ # GET /accidents/1
+ # GET /accidents/1.json
+ def show
+ @accident = Accident.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @accident }
+ end
+ end
+
+ # GET /accidents/new
+ # GET /accidents/new.json
+ def new
+ @accident = Accident.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @accident }
+ end
+ end
+
+ # GET /accidents/1/edit
+ def edit
+ @accident = Accident.find(params[:id])
+ end
+
+ # POST /accidents
+ # POST /accidents.json
+ def create
+ @accident = Accident.new(params[:accident])
+
+ respond_to do |format|
+ if @accident.save
+ format.html { redirect_to @accident, notice: 'Accident was successfully created.' }
+ format.json { render json: @accident, status: :created, location: @accident }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @accident.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /accidents/1
+ # PUT /accidents/1.json
+ def update
+ @accident = Accident.find(params[:id])
+
+ respond_to do |format|
+ if @accident.update_attributes(params[:accident])
+ format.html { redirect_to @accident, notice: 'Accident was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @accident.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /accidents/1
+ # DELETE /accidents/1.json
+ def destroy
+ @accident = Accident.find(params[:id])
+ @accident.destroy
+
+ respond_to do |format|
+ format.html { redirect_to accidents_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
6 app/controllers/index_controller.rb
@@ -1,6 +0,0 @@
-class IndexController < ApplicationController
- def index
- @accident_count = Accident.coordinates_available.count
- @accident = Accident.coordinates_available.all
- end
-end
View
2  app/helpers/accidents_helper.rb
@@ -0,0 +1,2 @@
+module AccidentsHelper
+end
View
0  app/models/.gitkeep
No changes.
View
5 app/models/accident.rb
@@ -1,7 +1,2 @@
class Accident < ActiveRecord::Base
- geocoded_by :location
- before_save :geocode
-
- scope :most_fatal, order("fatalities DESC").limit(100)
- scope :coordinates_available, where('LENGTH(longitude) > 0')
end
View
17 app/views/accidents/_form.html.erb
@@ -0,0 +1,17 @@
+<%= form_for(@accident) do |f| %>
+ <% if @accident.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@accident.errors.count, "error") %> prohibited this accident from being saved:</h2>
+
+ <ul>
+ <% @accident.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/accidents/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing accident</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @accident %> |
+<%= link_to 'Back', accidents_path %>
View
21 app/views/accidents/index.html.erb
@@ -0,0 +1,21 @@
+<h1>Listing accidents</h1>
+
+<table>
+ <tr>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @accidents.each do |accident| %>
+ <tr>
+ <td><%= link_to 'Show', accident %></td>
+ <td><%= link_to 'Edit', edit_accident_path(accident) %></td>
+ <td><%= link_to 'Destroy', accident, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Accident', new_accident_path %>
View
5 app/views/accidents/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New accident</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', accidents_path %>
View
5 app/views/accidents/show.html.erb
@@ -0,0 +1,5 @@
+<p id="notice"><%= notice %></p>
+
+
+<%= link_to 'Edit', edit_accident_path(@accident) %> |
+<%= link_to 'Back', accidents_path %>
View
4 app/views/index/index.html.erb
@@ -1,4 +0,0 @@
-<%= @accident_count %><br />
-<% @accident.each do |a| %>
- <%= a.location %> - <%= a.latitude %> - <%= a.longitude %> <br />
-<% end %>
View
4 config/routes.rb
@@ -1,4 +1,6 @@
Placcidents::Application.routes.draw do
+ resources :accidents
+
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -55,5 +57,5 @@
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id))(.:format)'
- root :to => 'index#index'
+ root :to => 'accidents#index'
end
View
21 db/migrate/20120207152645_create_accidents.rb
@@ -1,21 +0,0 @@
-class CreateAccidents < ActiveRecord::Migration
- def up
- create_table :accidents do |p|
- p.string :checksum
- p.date :date
- p.string :location
- p.string :operator
- p.string :aircraft_type
- p.string :registration
- p.integer :fatalities
- p.integer :total_passengers
- p.integer :ground_fatalities
- p.float :latitude
- p.float :longitude
- end
- end
-
- def down
- drop_table :accidents
- end
-end
View
8 db/migrate/20120214203110_create_accidents.rb
@@ -0,0 +1,8 @@
+class CreateAccidents < ActiveRecord::Migration
+ def change
+ create_table :accidents do |t|
+
+ t.timestamps
+ end
+ end
+end
View
43 lib/tasks/rakeplaneinfo.rake
@@ -1,43 +0,0 @@
-require 'mechanize'
-
-task :plane_info do |plane|
- mech = Mechanize.new
- # Load the main page
- mech.get('http://planecrashinfo.com/database.htm') do |main_page|
- # Parse out all the links on the main table
- link_table = main_page.search('table')[1].search('tr').search('td').map{ |n| n.text }
-
- # Try to go to each valid link and load the data from the table on the page
- link_table.each do |year|
- year = year.gsub(/[^0-9 ]/, '')
- if year.length > 0 && year.length < 6
- year_page = main_page.link_with(:text => year).click
- row_data = year_page.search('table').search('tr')
-
- count = 0;
- row_data.each do |row|
- puts row
- next if row
- if count > 0
- column_data = row.search('td').map{ |c| c.text }
- # p column_data
- end
- count+=1
- end
-
- # Now take the data which is csv format, and dump it into a model
- # lines = flight_data
- # header = lines.shift.strip
- # keys = header.split(',')
- # lines.each do |line|
- # params = {}
- # values = line.strip.split(',')
- # keys.each_with_index do |key,i|
- # params[key] = values[i]
- # end
- # Module.const_get(args[:model]).create(params)
- # end
- end
- end
- end
-end
View
49 test/functional/accidents_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class AccidentsControllerTest < ActionController::TestCase
+ setup do
+ @accident = accidents(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:accidents)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create accident" do
+ assert_difference('Accident.count') do
+ post :create, accident: @accident.attributes
+ end
+
+ assert_redirected_to accident_path(assigns(:accident))
+ end
+
+ test "should show accident" do
+ get :show, id: @accident
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @accident
+ assert_response :success
+ end
+
+ test "should update accident" do
+ put :update, id: @accident, accident: @accident.attributes
+ assert_redirected_to accident_path(assigns(:accident))
+ end
+
+ test "should destroy accident" do
+ assert_difference('Accident.count', -1) do
+ delete :destroy, id: @accident
+ end
+
+ assert_redirected_to accidents_path
+ end
+end
View
4 test/unit/helpers/accidents_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class AccidentsHelperTest < ActionView::TestCase
+end
Please sign in to comment.
Something went wrong with that request. Please try again.