Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support nested subforms of associations using :nested_attributes Sequ…

…el plugin.

The :strict option of nested_attributes must be set to 'false'.
  • Loading branch information...
commit 3731e1af4a44fcfef304342086b2481e9f8a1f49 1 parent 6a1eea1
@r-stu31 authored
View
2  lib/active_scaffold/attribute_params.rb
@@ -55,6 +55,8 @@ def update_record_from_params(parent_record, columns, attributes)
if multi_parameter_attributes.has_key? column.name
parent_record.send(:assign_multiparameter_attributes, multi_parameter_attributes[column.name])
+ elsif column.nested and attributes.has_key? column.nested_attribute_name
+ parent_record.send("#{column.nested_attribute_name}=", attributes[column.nested_attribute_name])
elsif attributes.has_key? column.name.to_s
value = column_value_from_param_value(parent_record, column, attributes[column.name.to_s])
# we avoid assigning a value that already exists because otherwise has_one associations will break (AR bug in has_one_association.rb#replace)
View
8 lib/active_scaffold/data_structures/column.rb
@@ -220,6 +220,13 @@ def show_blank_record?(associated)
cattr_accessor :association_form_ui
@@association_form_ui = nil
+ # boolean: true if the column is for a nested association, otherwise nil
+ attr_accessor :nested
+
+ def nested_attribute_name
+ @nested_attribute_name ||= "#{name}_attributes"
+ end
+
# ----------------------------------------------------------------- #
# the below functionality is intended for internal consumption only #
# ----------------------------------------------------------------- #
@@ -270,6 +277,7 @@ def initialize(name, active_record_class) #:nodoc:
self.name = name
@column = active_record_class.db_schema[name]
@association = active_record_class.association_reflection(name)
+ @nested = true if @association and @association[:nested_attributes]
@autolink = !@association.nil?
@active_record_class = active_record_class
@table = active_record_class.table_name
View
5 lib/active_scaffold/helpers/form_column_helpers.rb
@@ -289,10 +289,11 @@ def column_renders_as(column)
end
def column_scope(column)
+ name = column.nested ? column.nested_attribute_name : column.name
if column.plural_association?
- "[#{column.name}][#{@record.id || generate_temporary_id}]"
+ "[#{name}][#{@record.id || generate_temporary_id}]"
else
- "[#{column.name}]"
+ "[#{name}]"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.