Adding versioning

This commit is contained in:
Will Bradley 2013-10-09 03:34:27 -07:00
parent 5a94d69b3d
commit ebc696814e
11 changed files with 101 additions and 46 deletions

View File

@ -43,3 +43,7 @@ end
# Use debugger # Use debugger
# gem 'debugger', group: [:development, :test] # gem 'debugger', group: [:development, :test]
gem 'paper_trail', '>= 3.0.0.beta1'
gem 'gmaps4rails'

View File

@ -52,6 +52,8 @@ GEM
mime-types (1.25) mime-types (1.25)
minitest (4.7.5) minitest (4.7.5)
multi_json (1.8.1) multi_json (1.8.1)
paper_trail (3.0.0.beta1)
activerecord (>= 3.0, < 5.0)
polyglot (0.3.3) polyglot (0.3.3)
rack (1.5.2) rack (1.5.2)
rack-test (0.6.2) rack-test (0.6.2)
@ -111,6 +113,7 @@ DEPENDENCIES
coffee-rails (~> 4.0.0) coffee-rails (~> 4.0.0)
jbuilder (~> 1.2) jbuilder (~> 1.2)
jquery-rails jquery-rails
paper_trail (>= 3.0.0.beta1)
rails (= 4.0.0) rails (= 4.0.0)
sass-rails (~> 4.0.0) sass-rails (~> 4.0.0)
sdoc sdoc

View File

@ -2,4 +2,8 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception. # Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception protect_from_forgery with: :exception
def info_for_paper_trail
{ :whodunnit => request.remote_ip }
end
end end

View File

@ -1,2 +1,3 @@
class Space < ActiveRecord::Base class Space < ActiveRecord::Base
has_paper_trail
end end

View File

@ -16,8 +16,8 @@
<%= f.text_field :name %> <%= f.text_field :name %>
</div> </div>
<div class="field"> <div class="field">
<%= f.label :type %><br> <%= f.label :category %><br>
<%= f.text_field :type %> <%= f.text_field :category %>
</div> </div>
<div class="field"> <div class="field">
<%= f.label :address %><br> <%= f.label :address %><br>

View File

@ -0,0 +1,40 @@
<p>
<strong>Name:</strong>
<%= space.name %>
</p>
<p>
<strong>Category:</strong>
<%= space.category %>
</p>
<p>
<strong>Address:</strong>
<%= space.address %>
</p>
<p>
<strong>Hours:</strong>
<%= space.hours %>
</p>
<p>
<strong>Phone:</strong>
<%= space.phone %>
</p>
<p>
<strong>Email:</strong>
<%= space.email %>
</p>
<p>
<strong>Website:</strong>
<%= space.website %>
</p>
<p>
<strong>Description:</strong>
<%= space.description %>
</p>

View File

@ -4,7 +4,7 @@
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Type</th> <th>Category</th>
<th>Address</th> <th>Address</th>
<th>Hours</th> <th>Hours</th>
<th>Phone</th> <th>Phone</th>
@ -21,7 +21,7 @@
<% @spaces.each do |space| %> <% @spaces.each do |space| %>
<tr> <tr>
<td><%= space.name %></td> <td><%= space.name %></td>
<td><%= space.type %></td> <td><%= space.category %></td>
<td><%= space.address %></td> <td><%= space.address %></td>
<td><%= space.hours %></td> <td><%= space.hours %></td>
<td><%= space.phone %></td> <td><%= space.phone %></td>

View File

@ -1,44 +1,18 @@
<p id="notice"><%= notice %></p> <p id="notice"><%= notice %></p>
<p> <%= render partial: "space", locals: {space: @space} %>
<strong>Name:</strong>
<%= @space.name %>
</p>
<p>
<strong>Type:</strong>
<%= @space.type %>
</p>
<p>
<strong>Address:</strong>
<%= @space.address %>
</p>
<p>
<strong>Hours:</strong>
<%= @space.hours %>
</p>
<p>
<strong>Phone:</strong>
<%= @space.phone %>
</p>
<p>
<strong>Email:</strong>
<%= @space.email %>
</p>
<p>
<strong>Website:</strong>
<%= @space.website %>
</p>
<p>
<strong>Description:</strong>
<%= @space.description %>
</p>
<%= link_to 'Edit', edit_space_path(@space) %> | <%= link_to 'Edit', edit_space_path(@space) %> |
<%= link_to 'Back', spaces_path %> <%= link_to 'Back', spaces_path %>
<h3>Revision history</h3>
<dl>
<% @space.versions.each do |v| %>
<dt><b><%= v.event.capitalize %> <%= v.created_at %> <%= v.whodunnit if v.whodunnit %></b></dt>
<dd>
<% if v.reify %>
<%= render partial: "space", locals: {space: v.reify} %>
<% end %>
</dd>
<% end %>
</dl>

View File

@ -2,7 +2,7 @@ class CreateSpaces < ActiveRecord::Migration
def change def change
create_table :spaces do |t| create_table :spaces do |t|
t.string :name t.string :name
t.string :type t.string :category
t.string :address t.string :address
t.string :hours t.string :hours
t.string :phone t.string :phone

View File

@ -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

View File

@ -11,11 +11,11 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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| create_table "spaces", force: true do |t|
t.string "name" t.string "name"
t.string "type" t.string "category"
t.string "address" t.string "address"
t.string "hours" t.string "hours"
t.string "phone" t.string "phone"
@ -26,4 +26,15 @@ ActiveRecord::Schema.define(version: 20131009050712) do
t.datetime "updated_at" t.datetime "updated_at"
end 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 end