Token导航 LogoToken导航TokenDH.com
待分类权限需确认github未标认证来源可访问许可证需确认审计通过

dynamic-nested-attributes动态嵌套属性

Agent Skill

dynamic-nested-attributes 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

552

周安装

23

GitHub Stars

5

下载量

184
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:dynamic-nested-attributes(动态嵌套属性)
来源仓库:https://github.com/rolemodel/rolemodel-skills
仓库路径:skills/dynamic-nested-attributes
安装命令:
npx skills add https://github.com/rolemodel/rolemodel-skills --skill dynamic-nested-attributes
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/rolemodel/rolemodel-skills --skill dynamic-nested-attributes

简介

dynamic-nested-attributes 实现 Rails 嵌套属性动态增删功能,结合 Turbo Streams 无刷新更新。

  • 适用于用户批量编辑关联记录(如订单项、子任务)的表单场景。
  • 使用 accepts_nested_attributes_for 与 JavaScript 事件驱动 DOM 更新。
  • 需确认 Simple Form 或 Formtastic 等表单 gem 已正确配置。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Dynamic Nested Attributes

Overview

Implement Rails nested attributes with dynamic add/remove functionality using Turbo Streams and Simple Form. This pattern allows users to add and remove associated records inline within a parent form.

When to Use

  • Building forms where users need to manage multiple child records (has_many associations)
  • Adding/removing nested items without page refresh
  • Bulk creation or editing of associated records
  • Forms requiring progressive disclosure of additional fields

Key Components

1. Form Object or Model

  • Accepts nested attributes for the association
  • Use accepts_nested_attributes_for:association_name in the model or form object

2. Main Form View

Create a form that includes:

  • simple_fields_for for rendering existing nested items
  • A container element with an ID for appending new items (e.g., #accessories)
  • A link to add new items that triggers a Turbo Stream request

Example:

= simple_form_for resource do |f|
  = f.simple_fields_for :items do |ff|
    = render 'item_fields', f: ff, resource:

= render 'add_button', index: resource.items.size

Add Button Partial (_add_button.html.slim):

-# locals: (index:)
= link_to icon('add'), new_parent_item_path(index: index),
  id: 'add_button', class: 'btn', data: { turbo_stream: true }

3. Nested Fields Partial

Create a partial (e.g., _item_fields.html.slim) that:

  • Wraps fields in a unique container with an ID based on index
  • Includes a data controller for remove functionality
  • Shows a delete button for all records
  • Includes all form inputs for the nested item

Example:

fieldset id="item_#{f.index}" controller='destroy-nested-attributes'
  = f.hidden_field :_destroy, data: { destroy_nested_attributes_target: 'input' }
  = f.input :name
  = f.input :quantity
  .form-row__actions
    = button_tag icon('delete'), type: 'button', class: 'btn btn-delete',
      data: { action: 'destroy-nested-attributes#perform' }

4. Controller Actions

Implement a new action that:

  • Builds a new nested item
  • Accepts index parameter for tracking position

Example:

def new
  @item = Item.new
end

5. Turbo Stream Response

Create a new.turbo_stream.slim view that:

  • Updates the "add" button with incremented index
  • Appends the new nested fields to the container
  • Uses index parameter to ensure unique field names
  • Works with non-persisted parents by using a symbol and empty URL

Example:

= turbo_stream.replace 'add_button', partial: 'add_button', locals: { index: params[:index].to_i + 1 }

= simple_form_for :parent, url: '' do |f|
  = f.simple_fields_for :items_attributes, @item, index: params[:index] do |ff|
    = turbo_stream.append 'items', partial: 'item_fields', locals: { f: ff }

6. Remove Stimulus Controller

Create a Stimulus controller to handle client-side removal:

Example JavaScript:

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ['input']
  static classes = ['destroyed']

  connect() {
    if (!this.hasDestroyedClass) {
      this.element.setAttribute(`data-${this.identifier}-destroyed-class`, 'is-hidden')
    }
  }

  perform() {
    this.inputTarget.value = '1'
    this.element.classList.add(this.destroyedClass)
  }
}

Implementation Checklist

  • Add accepts_nested_attributes_for to model/form object
  • Create main form with simple_fields_for and container element
  • Create nested fields partial with remove functionality
  • Implement controller new action with index support
  • Create turbo_stream response view
  • Add Stimulus controller for client-side removal
  • Update routes to support nested resource creation
  • Update strong parameters to permit nested attributes
  • Add policy authorization if using Pundit

Common Patterns

Dynamic Collections Based on Parent Selection

Pass filtered collections to nested partials:

= render 'item_fields', f: ff, resource:, collection: resource.items

Routes Example

If there is not an existing new route in use, use the following pattern

resources :items, only: [:new]

If one does exist, create a new namespaced controller

namespace :parent do
  resources :items, only: [:new]
end

Strong Parameters Example

def item_params
  params.require(:parent).permit(
    :category,
    :subcategory,
    items_attributes: %i[
      name
      quantity
      part_id
      optional
      hidden
    ]
  )
end

Related Patterns

  • Turbo Frame inline editing
  • Stimulus data controller integration
  • Form object pattern for bulk operations
  • Policy-scoped collections for associations

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.92%
按下载量换算68

Claude

28.79%
按下载量换算53

Cursor

17.3%
按下载量换算32

Gemini CLI

9.78%
按下载量换算18

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

权限需确认

当前来源未能明确判断权限范围,默认进入异常复核队列。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills