Skip to content

Commit

Permalink
Solved issue with attributes not being assigned
Browse files Browse the repository at this point in the history
  • Loading branch information
brenes committed Jun 7, 2016
1 parent 82a8078 commit 77d9b18
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/models/no_cms/blocks/concerns/serializing_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ def save_related_objects
end
end

##
# Implementing the respond_to_missing? so respond_to? also check for
# the methods responded via the method_missing.
# This also solves an issue with attributes not assigned in rails 5.
#
# We just check that there's a field. If there's not then we delegate
# in the super implementation.
def respond_to_missing? method_name, include_private = false
# We get the name of the field stripping out the '=' for writers
field = method_name.to_s.gsub(/\=$/, '')
has_field?(field) || super
end

##
# In this missing method we check wether we're asking for one field
# in which case we will read or write it.
Expand Down Expand Up @@ -289,7 +302,6 @@ def assign_attributes new_attributes
" in #{self.layout} layout #{is_translation? ? 'translation' : ''}"

# And now separate fields and attributes
debugger
fields = new_attributes.select{|k, _| has_field? k }.symbolize_keys
# Now we filter those fields we must not manage because we are (or
# not) in a translation. I.e: if we have a translated field, but we
Expand Down

0 comments on commit 77d9b18

Please sign in to comment.