diff --git a/Gemfile b/Gemfile
index 30d54d4..0ccc95e 100644
--- a/Gemfile
+++ b/Gemfile
@@ -43,3 +43,7 @@ end
# Use debugger
# gem 'debugger', group: [:development, :test]
+
+gem 'paper_trail', '>= 3.0.0.beta1'
+
+gem 'gmaps4rails'
\ No newline at end of file
diff --git a/Gemfile.lock b/Gemfile.lock
index c0a9b17..278b695 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -52,6 +52,8 @@ GEM
mime-types (1.25)
minitest (4.7.5)
multi_json (1.8.1)
+ paper_trail (3.0.0.beta1)
+ activerecord (>= 3.0, < 5.0)
polyglot (0.3.3)
rack (1.5.2)
rack-test (0.6.2)
@@ -111,6 +113,7 @@ DEPENDENCIES
coffee-rails (~> 4.0.0)
jbuilder (~> 1.2)
jquery-rails
+ paper_trail (>= 3.0.0.beta1)
rails (= 4.0.0)
sass-rails (~> 4.0.0)
sdoc
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index d83690e..4c62345 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -2,4 +2,8 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
+
+ def info_for_paper_trail
+ { :whodunnit => request.remote_ip }
+ end
end
diff --git a/app/models/space.rb b/app/models/space.rb
index 023adda..5a93e3d 100644
--- a/app/models/space.rb
+++ b/app/models/space.rb
@@ -1,2 +1,3 @@
class Space < ActiveRecord::Base
+ has_paper_trail
end
diff --git a/app/views/spaces/_form.html.erb b/app/views/spaces/_form.html.erb
index 4cfc26b..83277a2 100644
--- a/app/views/spaces/_form.html.erb
+++ b/app/views/spaces/_form.html.erb
@@ -16,8 +16,8 @@
<%= f.text_field :name %>
- <%= f.label :type %>
- <%= f.text_field :type %>
+ <%= f.label :category %>
+ <%= f.text_field :category %>
<%= f.label :address %>
diff --git a/app/views/spaces/_space.html.erb b/app/views/spaces/_space.html.erb
new file mode 100644
index 0000000..aa0b2b3
--- /dev/null
+++ b/app/views/spaces/_space.html.erb
@@ -0,0 +1,40 @@
+
+
+ Name:
+ <%= space.name %>
+
+
+
+ Category:
+ <%= space.category %>
+
+
+
+ Address:
+ <%= space.address %>
+
+
+
+ Hours:
+ <%= space.hours %>
+
+
+
+ Phone:
+ <%= space.phone %>
+
+
+
+ Email:
+ <%= space.email %>
+
+
+
+ Website:
+ <%= space.website %>
+
+
+
+ Description:
+ <%= space.description %>
+
\ No newline at end of file
diff --git a/app/views/spaces/index.html.erb b/app/views/spaces/index.html.erb
index 117bfaf..fb342d7 100644
--- a/app/views/spaces/index.html.erb
+++ b/app/views/spaces/index.html.erb
@@ -4,7 +4,7 @@
Name |
- Type |
+ Category |
Address |
Hours |
Phone |
@@ -21,7 +21,7 @@
<% @spaces.each do |space| %>
<%= space.name %> |
- <%= space.type %> |
+ <%= space.category %> |
<%= space.address %> |
<%= space.hours %> |
<%= space.phone %> |
diff --git a/app/views/spaces/show.html.erb b/app/views/spaces/show.html.erb
index 2477fda..ff60eb0 100644
--- a/app/views/spaces/show.html.erb
+++ b/app/views/spaces/show.html.erb
@@ -1,44 +1,18 @@
<%= notice %>
-
- Name:
- <%= @space.name %>
-
-
-
- Type:
- <%= @space.type %>
-
-
-
- Address:
- <%= @space.address %>
-
-
-
- Hours:
- <%= @space.hours %>
-
-
-
- Phone:
- <%= @space.phone %>
-
-
-
- Email:
- <%= @space.email %>
-
-
-
- Website:
- <%= @space.website %>
-
-
-
- Description:
- <%= @space.description %>
-
+<%= render partial: "space", locals: {space: @space} %>
<%= link_to 'Edit', edit_space_path(@space) %> |
<%= link_to 'Back', spaces_path %>
+
+Revision history
+
+<% @space.versions.each do |v| %>
+ - <%= v.event.capitalize %> <%= v.created_at %> <%= v.whodunnit if v.whodunnit %>
+ -
+ <% if v.reify %>
+ <%= render partial: "space", locals: {space: v.reify} %>
+ <% end %>
+
+<% end %>
+
\ No newline at end of file
diff --git a/db/migrate/20131009050712_create_spaces.rb b/db/migrate/20131009050712_create_spaces.rb
index 0692488..ac3f940 100644
--- a/db/migrate/20131009050712_create_spaces.rb
+++ b/db/migrate/20131009050712_create_spaces.rb
@@ -2,7 +2,7 @@ class CreateSpaces < ActiveRecord::Migration
def change
create_table :spaces do |t|
t.string :name
- t.string :type
+ t.string :category
t.string :address
t.string :hours
t.string :phone
diff --git a/db/migrate/20131009051102_create_versions.rb b/db/migrate/20131009051102_create_versions.rb
new file mode 100644
index 0000000..701f7ea
--- /dev/null
+++ b/db/migrate/20131009051102_create_versions.rb
@@ -0,0 +1,18 @@
+class CreateVersions < ActiveRecord::Migration
+ def self.up
+ create_table :versions do |t|
+ t.string :item_type, :null => false
+ t.integer :item_id, :null => false
+ t.string :event, :null => false
+ t.string :whodunnit
+ t.text :object
+ t.datetime :created_at
+ end
+ add_index :versions, [:item_type, :item_id]
+ end
+
+ def self.down
+ remove_index :versions, [:item_type, :item_id]
+ drop_table :versions
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 04d3aed..f50e863 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,11 +11,11 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20131009050712) do
+ActiveRecord::Schema.define(version: 20131009051102) do
create_table "spaces", force: true do |t|
t.string "name"
- t.string "type"
+ t.string "category"
t.string "address"
t.string "hours"
t.string "phone"
@@ -26,4 +26,15 @@ ActiveRecord::Schema.define(version: 20131009050712) do
t.datetime "updated_at"
end
+ create_table "versions", force: true do |t|
+ t.string "item_type", null: false
+ t.integer "item_id", null: false
+ t.string "event", null: false
+ t.string "whodunnit"
+ t.text "object"
+ t.datetime "created_at"
+ end
+
+ add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
+
end