mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 05:34:46 +02:00
Extract block to helper function
This commit is contained in:
parent
b0bec41f56
commit
a93228c579
4 changed files with 14 additions and 8 deletions
|
@ -1,5 +1,7 @@
|
|||
module Admin
|
||||
class ContactVersionsController < BaseController
|
||||
include ObjectVersionsHelper
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
|
|
10
app/helpers/object_versions_helper.rb
Normal file
10
app/helpers/object_versions_helper.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
module ObjectVersionsHelper
|
||||
def attach_existing_fields(version, new_object)
|
||||
version.object_changes.to_h.each do |k, v|
|
||||
method_name = "#{k}=".to_sym
|
||||
if new_object.respond_to?(method_name)
|
||||
new_object.public_send(method_name, v.last)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -56,10 +56,7 @@
|
|||
- @versions.each do |version|
|
||||
- if version
|
||||
- domain = Domain.new(version.object.to_h)
|
||||
- version.object_changes.to_h.each do |k, v|
|
||||
- method_name = "#{k}=".to_sym
|
||||
- if domain.respond_to?(method_name)
|
||||
- domain.public_send("#{k}=", v.last)
|
||||
- attach_existing_fields(version, domain)
|
||||
|
||||
%tr
|
||||
%td= link_to(domain.name, admin_domain_version_path(version.id))
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
- domain = Domain.new(@version.object.to_h)
|
||||
- @version.object_changes.to_h.each do |k, v|
|
||||
- method_name = "#{k}=".to_sym
|
||||
- if domain.respond_to?(method_name)
|
||||
- domain.public_send("#{k}=", v.last)
|
||||
- attach_existing_fields(@version, domain)
|
||||
|
||||
- if @version
|
||||
- children = HashWithIndifferentAccess.new(@version.children)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue