From 32b1ab88cbd74bf2147731cc0c7e6c8db95fc540 Mon Sep 17 00:00:00 2001 From: Lars Henrik Mai Date: Sat, 29 Mar 2014 16:48:54 +0100 Subject: added basic scaffold for pois --- app/assets/javascripts/pois.js.coffee | 3 ++ app/assets/stylesheets/pois.css.scss | 3 ++ app/assets/stylesheets/scaffolds.css.scss | 69 ++++++++++++++++++++++++++++ app/controllers/pois_controller.rb | 74 +++++++++++++++++++++++++++++++ app/helpers/pois_helper.rb | 2 + app/models/poi.rb | 2 + app/views/pois/_form.html.erb | 31 +++++++++++++ app/views/pois/edit.html.erb | 6 +++ app/views/pois/index.html.erb | 31 +++++++++++++ app/views/pois/index.json.jbuilder | 4 ++ app/views/pois/new.html.erb | 5 +++ app/views/pois/show.html.erb | 19 ++++++++ app/views/pois/show.json.jbuilder | 1 + 13 files changed, 250 insertions(+) create mode 100644 app/assets/javascripts/pois.js.coffee create mode 100644 app/assets/stylesheets/pois.css.scss create mode 100644 app/assets/stylesheets/scaffolds.css.scss create mode 100644 app/controllers/pois_controller.rb create mode 100644 app/helpers/pois_helper.rb create mode 100644 app/models/poi.rb create mode 100644 app/views/pois/_form.html.erb create mode 100644 app/views/pois/edit.html.erb create mode 100644 app/views/pois/index.html.erb create mode 100644 app/views/pois/index.json.jbuilder create mode 100644 app/views/pois/new.html.erb create mode 100644 app/views/pois/show.html.erb create mode 100644 app/views/pois/show.json.jbuilder (limited to 'app') 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? %> +
+

<%= pluralize(@poi.errors.count, "error") %> prohibited this poi from being saved:

+ + +
+ <% end %> + +
+ +
+ <%= f.label :message %>
+ <%= f.text_area :message %> +
+
+ <%= f.label :lat %>
+ <%= f.text_field :lat %> +
+
+ <%= f.label :lon %>
+ <%= f.text_field :lon %> +
+
+ <%= f.submit %> +
+<% 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 @@ +

Editing poi

+ +<%= 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 @@ +

Listing pois

+ + + + + + + + + + + + + + + <% @pois.each do |poi| %> + + + + + + + + + <% end %> + +
MessageLatLon
<%= poi.message %><%= poi.lat %><%= poi.lon %><%= link_to 'Show', poi %><%= link_to 'Edit', edit_poi_path(poi) %><%= link_to 'Destroy', poi, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= 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 @@ +

New poi

+ +<%= 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 @@ +

<%= notice %>

+ +

+ Message: + <%= @poi.message %> +

+ +

+ Lat: + <%= @poi.lat %> +

+ +

+ Lon: + <%= @poi.lon %> +

+ +<%= 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 -- cgit v1.2.1