# Templates with multiple files

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/ruby/2026.3/llms.txt).

Some programming patterns and frameworks require a set of related files, usually with a very specific structure.  For example, with the model-view-controller (MVC) pattern, you need separate files for the model, view, and controller.

In RubyMine, you can create sets of related files by adding child templates to a file template. When you create a file from such a template, it will also create files from child templates.

Procedure: Create a template with multiple files

1. In the Settings dialog (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Meta+Comma` (TextMate), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))), select `Editor | File and Code Templates`.

2. Create the main file template.

On the Files tab, click ![the Create Template button](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.add.svg) and specify the name, file extension, and body of the template.

3. Select the new template in the list and click ![The Create Child Template File button](https://resources.jetbrains.com/help/img/idea/2026.3/app.fileTypes.addAny.svg) on the toolbar. Specify the name, file extension, and body of the child template.

> **Note:**
> All child templates share the [variables](file-template-variables.html) of the main file template.
>
>
>
>
>
> You cannot add child templates to the default file templates.

## Example: Template with several files

A parent template can have any number of child templates, and a single action creates all of them at once. This is useful whenever a class is never written alone. A [ViewComponent](https://viewcomponent.org/) is a good example: it always consists of a Ruby class and the template that the class renders.

Procedure:

1. In the Settings dialog (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Meta+Comma` (TextMate), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))), select `Editor | File and Code Templates`.

2. Create the component class template.

On the Files tab, click ![the Create Template button](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.add.svg) and specify the following:

* Name: `Ruby ViewComponent`

* Extension: `rb`

* File name: leave this field empty

Add the following code to the template body:

```RB
#set($part = "")
#set($parts = $NAME.split("_"))
#set($class_name = "")
#foreach($part in $parts)
#set($class_name = "${class_name}${part.substring(0,1).toUpperCase()}${part.substring(1)}")
#end
class ${class_name} < ViewComponent::Base
  def initialize(title:)
    @title = title
  end
end
```

Because the File name field is empty, the file is named exactly as you type it, and it is created in the directory in which you invoke the template, for example: `app/components/example_component.rb`.

![A ViewComponent class is created](https://resources.jetbrains.com/help/img/idea/2026.3/rm_multiple_files_template_example_class.png)

> **Tip:**
> Every variable that is neither predefined nor assigned with `#set` becomes an input field in the dialog that RubyMine shows when you use the template. This is why the loop variable `$part` is assigned an empty value before the loop: without that line, the dialog would ask you to fill it in.

3. Create the template file.

Select the new Ruby ViewComponent template in the list and click ![The Create Child Template File button](https://resources.jetbrains.com/help/img/idea/2026.3/app.fileTypes.addAny.svg) on the toolbar. Specify the following:

* File name: `${NAME}/${NAME}.html`

* Extension: `erb`

Add the following code to the template body:

```HTML
<div class="example-component">
  <h2><%= @title %></h2>
</div>
```

A child template reuses the variables of its parent, so `${NAME}` resolves to the same name in both files: the template belongs to the class that the parent template creates. A child template also has its own Extension, which is how one action can produce files of different types, for example: `app/components/example_component/example_component.html.erb`.

![Adding a child file to a file template](https://resources.jetbrains.com/help/img/idea/2026.3/rm_multiple_files_template_child_file.png)

4. Click OK to apply the changes.

5. To use the new template, do the following:

1.

Right-click the directory in the Project tool window or press `Alt+Insert` (Windows), `⌘ N` (macOS), `⌃ N` (IntelliJ IDEA Classic (macOS)), `⌘ N` (macOS System Shortcuts), `Alt+Insert` (XWin), `Alt+Insert` (GNOME), `Alt+Insert` (KDE), `Alt+Insert` (Emacs), `Ctrl+N` (Sublime Text), `⌘ N` (Sublime Text (macOS)), `Ctrl+N` (Visual Studio), `⌘ N` (Visual Studio (macOS)), `Meta+Shift+N` (TextMate), `Alt+Insert` (NetBeans), `Alt+Insert` (Eclipse), `⌘ N` (Eclipse (macOS)), and select the Ruby ViewComponent template.

![Creating multiple files using a template](https://resources.jetbrains.com/help/img/idea/2026.3/rm_create_files_using_templates.png)

2. Specify a file name in `snake_case`, for example `example_component`, and RubyMine will create both files.

![Two files created using a file template](https://resources.jetbrains.com/help/img/idea/2026.3/rm_multiple_files_created_using_template.png)

