# Extract partial

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

> **TL;DR**
> `Refactor | Extract/Introduce | Partial`

The Extract Partial refactoring allows you to remove duplication in a view by extracting its fragment to a partial view. You can apply this refactoring to `.html.erb` and `.html.haml` files.

To extract a view fragment to a partial view, do the following:

Procedure:

1. Open a view in the editor and select the valid code fragment. For example, in case of HTML, your selection must contain matching opening and closing tags.

2. From the main menu or from the context menu of the selection, select `Refactor | Extract/Introduce | Partial`.

![Extract partial](https://resources.jetbrains.com/help/img/idea/2026.3/rm_extract_partial_menu.png)

3. In the Extract Partial dialog, specify the desired partial view name without the extension and leading underscore, and click OK.

![Extract Partial dialog](https://resources.jetbrains.com/help/img/idea/2026.3/rm_extract_partial_dialog.png)

RubyMine will move the selected code fragment and replace it with a corresponding call.

## Example

Before:

```HTML
<!--'new.html.erb' file-->
<h1>New article</h1>
<%= form_with scope: :article, local: true do |form| %>
<p>
    <%= form.label :title %><br>
    <%= form.text_field :title %>
</p>
<p>
    <%= form.label :text %><br>
    <%= form.text_area :text %>
</p>
<p>
    <%= form.submit %>
</p>
<% end %>
<%= link_to 'Back', articles_path %>

```

After:

```HTML
<!--'new.html.erb' file-->
<h1>New article</h1>
<%= render 'form' %>
<%= link_to 'Back', articles_path %>
<!---->
<!--'_form.html.erb' file-->
<%= form_with scope: :article, local: true do |form| %>
<p>
    <%= form.label :title %><br>
    <%= form.text_field :title %>
</p>
<p>
    <%= form.label :text %><br>
    <%= form.text_area :text %>
</p>
<p>
    <%= form.submit %>
</p>
<% end %>
```

## See also

### Procedures

[Navigate to a related Rails entity using gutter icons](product-specific-navigation.html#navigate_gutter_icons)

