Sha256: df55a964c242b0f1c1bb3c7aa04397c8be6744aabdf0bbe55d99761518ec7d6a
Contents?: true
Size: 1.15 KB
Versions: 4
Compression:
Stored size: 1.15 KB
Contents
module NestedFieldsHelper def nested_fields_for(f, association, options={}, &block) reflection = f.object.class.reflect_on_association(association) is_has_one = reflection.macro == :has_one options[:nested_partial] ||= "#{is_has_one ? association.to_s.pluralize : association}/fields" add = add_nested_fields_path :association => association, :builder => f.class, :nested_partial => options[:nested_partial], :parent_class => f.object.class, :parent_form => f.object_name partial = "nested_fields/#{'singular_' if is_has_one}nested_fieldset" locals = {:add_url => add, :association => association, :f => f} locals.merge!(options) if is_has_one associate = f.object.send(association); if associate.nil? locals[:associate] = reflection.klass.new locals[:has_zero] = true else locals[:associate] = associate end end if block_given? render :layout => partial, :locals => locals, &block else render partial, locals end end end
Version data entries
4 entries across 4 versions & 1 rubygems