· 1 min read

Screencast: Undo mit Paper Trail

div> 

Download:

Download(20.5 MB, 13:22) Alternativer Download für iPod & Apple TV(19.7 MB, 13:22)

Resourcen:

Quellcode:

[bash] bundle rails g paper_trail:install rake db:migrate rails g controller versions [/bash]

[ruby] # Gemfile gem ‘paper_trail’

# products_controller def undo_link view_context.link_to(“undo”, revert_version_path(@product.versions.scoped.last), :method => :post) end

# routes.rb post “versions/:id/revert” => “versions#revert”, :as => “revert_version”

# versions_controller def revert @version = Version.find(params[:id]) if @version.reify @version.reify.save! else @version.item.destroy end link_name = params[:redo] == “true” ? “undo” : “redo” link = view_context.link_to(link_name, revert_version_path(@version.next, :redo => !params[:redo]), :method => :post) redirect_to :back, :notice => “Undid #{@version.event}. #{link}” end [/ruby]

Back to Blog