Extract 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:
-
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.
-
From the main menu, or from the context menu of the selection, select
. -
In the Extract Partial dialog, specify the desired partial view name without the extension and leading underscore, and click OK.
RubyMine will move the selected code fragment and replace it with a corresponding call.
Example
Before | After |
---|---|
<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 %>
|
<h1>New article</h1>
<%= render 'form' %>
<%= link_to 'Back', articles_path %>
<%= 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 %>
|