summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Henrik Mai <lars.mai@kontinui.de>2014-03-29 16:48:54 +0100
committerLars Henrik Mai <lars.mai@kontinui.de>2014-03-29 16:49:22 +0100
commit32b1ab88cbd74bf2147731cc0c7e6c8db95fc540 (patch)
tree57900fd451368f2609f6314d166741d98a4de0f6
parent90121413900895958a2ed8daaae2ab1e7dde996d (diff)
added basic scaffold for pois
-rw-r--r--app/assets/javascripts/pois.js.coffee3
-rw-r--r--app/assets/stylesheets/pois.css.scss3
-rw-r--r--app/assets/stylesheets/scaffolds.css.scss69
-rw-r--r--app/controllers/pois_controller.rb74
-rw-r--r--app/helpers/pois_helper.rb2
-rw-r--r--app/models/poi.rb2
-rw-r--r--app/views/pois/_form.html.erb31
-rw-r--r--app/views/pois/edit.html.erb6
-rw-r--r--app/views/pois/index.html.erb31
-rw-r--r--app/views/pois/index.json.jbuilder4
-rw-r--r--app/views/pois/new.html.erb5
-rw-r--r--app/views/pois/show.html.erb19
-rw-r--r--app/views/pois/show.json.jbuilder1
-rw-r--r--config/routes.rb3
-rw-r--r--db/migrate/20140329152147_create_pois.rb11
-rw-r--r--db/schema.rb27
-rw-r--r--test/controllers/pois_controller_test.rb49
-rw-r--r--test/fixtures/pois.yml11
-rw-r--r--test/helpers/pois_helper_test.rb4
-rw-r--r--test/models/poi_test.rb7
20 files changed, 362 insertions, 0 deletions
diff --git a/app/assets/javascripts/pois.js.coffee b/app/assets/javascripts/pois.js.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/pois.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://coffeescript.org/
diff --git a/app/assets/stylesheets/pois.css.scss b/app/assets/stylesheets/pois.css.scss
new file mode 100644
index 0000000..c3c4474
--- /dev/null
+++ b/app/assets/stylesheets/pois.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the pois controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss
new file mode 100644
index 0000000..6ec6a8f
--- /dev/null
+++ b/app/assets/stylesheets/scaffolds.css.scss
@@ -0,0 +1,69 @@
+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;
+ }
+}
diff --git a/app/controllers/pois_controller.rb b/app/controllers/pois_controller.rb
new file mode 100644
index 0000000..99b6e8a
--- /dev/null
+++ b/app/controllers/pois_controller.rb
@@ -0,0 +1,74 @@
+class PoisController < ApplicationController
+ before_action :set_poi, only: [:show, :edit, :update, :destroy]
+
+ # GET /pois
+ # GET /pois.json
+ def index
+ @pois = Poi.all
+ end
+
+ # GET /pois/1
+ # GET /pois/1.json
+ def show
+ end
+
+ # GET /pois/new
+ def new
+ @poi = Poi.new
+ end
+
+ # GET /pois/1/edit
+ def edit
+ end
+
+ # POST /pois
+ # POST /pois.json
+ def create
+ @poi = Poi.new(poi_params)
+
+ respond_to do |format|
+ if @poi.save
+ format.html { redirect_to @poi, notice: 'Poi was successfully created.' }
+ format.json { render action: 'show', status: :created, location: @poi }
+ else
+ format.html { render action: 'new' }
+ format.json { render json: @poi.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PATCH/PUT /pois/1
+ # PATCH/PUT /pois/1.json
+ def update
+ respond_to do |format|
+ if @poi.update(poi_params)
+ format.html { redirect_to @poi, notice: 'Poi was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: 'edit' }
+ format.json { render json: @poi.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /pois/1
+ # DELETE /pois/1.json
+ def destroy
+ @poi.destroy
+ respond_to do |format|
+ format.html { redirect_to pois_url }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+ # Use callbacks to share common setup or constraints between actions.
+ def set_poi
+ @poi = Poi.find(params[:id])
+ end
+
+ # Never trust parameters from the scary internet, only allow the white list through.
+ def poi_params
+ params.require(:poi).permit(:message, :lat, :lon)
+ end
+end
diff --git a/app/helpers/pois_helper.rb b/app/helpers/pois_helper.rb
new file mode 100644
index 0000000..de50430
--- /dev/null
+++ b/app/helpers/pois_helper.rb
@@ -0,0 +1,2 @@
+module PoisHelper
+end
diff --git a/app/models/poi.rb b/app/models/poi.rb
new file mode 100644
index 0000000..c8ef1f1
--- /dev/null
+++ b/app/models/poi.rb
@@ -0,0 +1,2 @@
+class Poi < ActiveRecord::Base
+end
diff --git a/app/views/pois/_form.html.erb b/app/views/pois/_form.html.erb
new file mode 100644
index 0000000..26db79d
--- /dev/null
+++ b/app/views/pois/_form.html.erb
@@ -0,0 +1,31 @@
+<%= form_for(@poi) do |f| %>
+ <% if @poi.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@poi.errors.count, "error") %> prohibited this poi from being saved:</h2>
+
+ <ul>
+ <% @poi.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div id="map"></div>
+
+ <div class="field">
+ <%= f.label :message %><br>
+ <%= f.text_area :message %>
+ </div>
+ <div class="field">
+ <%= f.label :lat %><br>
+ <%= f.text_field :lat %>
+ </div>
+ <div class="field">
+ <%= f.label :lon %><br>
+ <%= f.text_field :lon %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
diff --git a/app/views/pois/edit.html.erb b/app/views/pois/edit.html.erb
new file mode 100644
index 0000000..71dd920
--- /dev/null
+++ b/app/views/pois/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing poi</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @poi %> |
+<%= link_to 'Back', pois_path %>
diff --git a/app/views/pois/index.html.erb b/app/views/pois/index.html.erb
new file mode 100644
index 0000000..0e1d1d1
--- /dev/null
+++ b/app/views/pois/index.html.erb
@@ -0,0 +1,31 @@
+<h1>Listing pois</h1>
+
+<table>
+ <thead>
+ <tr>
+ <th>Message</th>
+ <th>Lat</th>
+ <th>Lon</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <% @pois.each do |poi| %>
+ <tr>
+ <td><%= poi.message %></td>
+ <td><%= poi.lat %></td>
+ <td><%= poi.lon %></td>
+ <td><%= link_to 'Show', poi %></td>
+ <td><%= link_to 'Edit', edit_poi_path(poi) %></td>
+ <td><%= link_to 'Destroy', poi, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
+
+<br>
+
+<%= link_to 'New Poi', new_poi_path %>
diff --git a/app/views/pois/index.json.jbuilder b/app/views/pois/index.json.jbuilder
new file mode 100644
index 0000000..c0f24fe
--- /dev/null
+++ b/app/views/pois/index.json.jbuilder
@@ -0,0 +1,4 @@
+json.array!(@pois) do |poi|
+ json.extract! poi, :id, :message, :lat, :lon
+ json.url poi_url(poi, format: :json)
+end
diff --git a/app/views/pois/new.html.erb b/app/views/pois/new.html.erb
new file mode 100644
index 0000000..ea4ebe0
--- /dev/null
+++ b/app/views/pois/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New poi</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', pois_path %>
diff --git a/app/views/pois/show.html.erb b/app/views/pois/show.html.erb
new file mode 100644
index 0000000..77fdf0b
--- /dev/null
+++ b/app/views/pois/show.html.erb
@@ -0,0 +1,19 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <strong>Message:</strong>
+ <%= @poi.message %>
+</p>
+
+<p>
+ <strong>Lat:</strong>
+ <%= @poi.lat %>
+</p>
+
+<p>
+ <strong>Lon:</strong>
+ <%= @poi.lon %>
+</p>
+
+<%= link_to 'Edit', edit_poi_path(@poi) %> |
+<%= link_to 'Back', pois_path %>
diff --git a/app/views/pois/show.json.jbuilder b/app/views/pois/show.json.jbuilder
new file mode 100644
index 0000000..5f4cf05
--- /dev/null
+++ b/app/views/pois/show.json.jbuilder
@@ -0,0 +1 @@
+json.extract! @poi, :id, :message, :lat, :lon, :created_at, :updated_at
diff --git a/config/routes.rb b/config/routes.rb
index 49a0316..f04e0b2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,4 +1,7 @@
Hfw::Application.routes.draw do
+
+ resources :pois
+
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
diff --git a/db/migrate/20140329152147_create_pois.rb b/db/migrate/20140329152147_create_pois.rb
new file mode 100644
index 0000000..a69cfe5
--- /dev/null
+++ b/db/migrate/20140329152147_create_pois.rb
@@ -0,0 +1,11 @@
+class CreatePois < ActiveRecord::Migration
+ def change
+ create_table :pois do |t|
+ t.text :message
+ t.decimal :lat
+ t.decimal :lon
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644
index 0000000..9c745d6
--- /dev/null
+++ b/db/schema.rb
@@ -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 that you check this file into your version control system.
+
+ActiveRecord::Schema.define(version: 20140329152147) do
+
+ # These are extensions that must be enabled in order to support this database
+ enable_extension "plpgsql"
+
+ create_table "pois", force: true do |t|
+ t.text "message"
+ t.decimal "lat"
+ t.decimal "lon"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
diff --git a/test/controllers/pois_controller_test.rb b/test/controllers/pois_controller_test.rb
new file mode 100644
index 0000000..8e08206
--- /dev/null
+++ b/test/controllers/pois_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class PoisControllerTest < ActionController::TestCase
+ setup do
+ @poi = pois(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:pois)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create poi" do
+ assert_difference('Poi.count') do
+ post :create, poi: { lat: @poi.lat, lon: @poi.lon, message: @poi.message }
+ end
+
+ assert_redirected_to poi_path(assigns(:poi))
+ end
+
+ test "should show poi" do
+ get :show, id: @poi
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @poi
+ assert_response :success
+ end
+
+ test "should update poi" do
+ patch :update, id: @poi, poi: { lat: @poi.lat, lon: @poi.lon, message: @poi.message }
+ assert_redirected_to poi_path(assigns(:poi))
+ end
+
+ test "should destroy poi" do
+ assert_difference('Poi.count', -1) do
+ delete :destroy, id: @poi
+ end
+
+ assert_redirected_to pois_path
+ end
+end
diff --git a/test/fixtures/pois.yml b/test/fixtures/pois.yml
new file mode 100644
index 0000000..5a20594
--- /dev/null
+++ b/test/fixtures/pois.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ message: MyText
+ lat: 9.99
+ lon: 9.99
+
+two:
+ message: MyText
+ lat: 9.99
+ lon: 9.99
diff --git a/test/helpers/pois_helper_test.rb b/test/helpers/pois_helper_test.rb
new file mode 100644
index 0000000..f438f4a
--- /dev/null
+++ b/test/helpers/pois_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class PoisHelperTest < ActionView::TestCase
+end
diff --git a/test/models/poi_test.rb b/test/models/poi_test.rb
new file mode 100644
index 0000000..a03fdf2
--- /dev/null
+++ b/test/models/poi_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PoiTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end