Saturday, May 13, 2023
HomeRuby On RailsInvestigating with Proof|Wandering Ruby

Investigating with Proof|Wandering Ruby


 # Gemfile

. treasure' paper_trail'

#
Terminal 
. rails g papertrail: mount

. rails db: move
 # config/initializers/paper _ trail.rb

. PaperTrail.config.track _ organizations = incorrect

. PaperTrail.config.version _ limitation = 3

. PaperTrail.serializer = PaperTrail:: Serializers:: JSON

.

. PaperTrail:: Version.class _ eval do

. def changed_object 
. @changed_object|| = JSON.parse( self.object, object_class: OpenStruct)

.
end 
.
end(* )# user.rb 
. course Customer < ApplicationRecord 
.
has_paper_trail on: 
, just: [:update, :destroy]

. end[:first_name, :last_name]<# show.html.erb 
.
<< h2>>
Variations< 
.
< table course=">table" >< << thead > <. << tr>> .<< th>> ID< .<< th>> Modifier< .<< th>> Activity <. < th > . . .
<< tbody > . . . . <. < .
.
. < li course= " list-group-item" >< < solid > Given Name:
. < <. < .
< li course= "list-group-item" > << solid>> Surname:
< . <. < .
<< li course= "list-group-item" > << solid > Email: <. . . < %( *) end % > . < % end < % > . < % end( *
) % > . < % end % > .
# application_controller. rb . course ApplicationController < ActionController:: Base . protect_from_forgery with:: exemption . before_action: set_paper_trail_whodunnit . . def user_for_paper_trail . # user_signed_in?? current_user. id: 'Public customer' .
' Public customer' . end .
end # routes.rb . Rails.application.routes.draw do . sources: customers do .
obtain: rollback
. end .
origin to:' customers #index' .
end # users_controller.
rb . def rollback .
@user = User.find( params
) . variation = @user. versions.find( params )
. if version.reify.save . redirect_to @user, notification: 'Customer was effectively rollbacked.' .
else .
provide: program .
end .
end
.

RELATED ARTICLES

Most Popular

Recent Comments