· 1 min read
Screencast: Model Versioning
Downloadlinks:
Download (14.4 MB, 9:28)
Alternativer Download für iPod & Apple TV (10.4 MB, 9:28)
Weitere Resourcen zu diesem Screencast:
Verwendung in der Konsole
[bash] sudo rake gems:install script/generate vestal_versions_migration script/generate migration version_existing_pages rake db:migrate [/bash]
Quellcode:
[ruby] # config/environment.rb config.gem ‘laserlemon-vestal_versions’, :lib => ‘vestal_versions’, :source => ‘http://gems.github.com’
# models/page.rb class Page < ActiveRecord::Base versioned end
# version_existing_pages migration say_with_time “Setting initial version for pages” do Page.find_each(&:touch) end
# pages_controller.rb def show @page = Page.find(params[:id]) @page.revert_to(params[:version].to_i) if params[:version] end
# script/console p = Page.all p.versions p.revert_to(7.minutes.ago) p.content p.revert_to(:last)
[/ruby]
[xhtml]
<%= link_to “Edit”, edit_page_path(@page) %> | Version <%= @page.version %> <% if @page.version > 1 %> | <%= link_to “Previous version”, :version => @page.version-1 %> <% end %> <% if params[:version] %> | <%= link_to “Latest version”, :version => nil %> <% end %>
[/xhtml]