IntelliJ IDEA 2016.3 Help

Extract Partial

This feature is supported only when the Ruby plugin is installed.

The Extract Partial refactoring enables you to break rendering of a certain view into smaller chunks, and applies to *.html.erb and *.html.haml files.

This way, you can extract blocks of code from a view into a partial view, and replace them with a call. So doing, IntelliJ IDEA generates the name for the resulting partial view on the base of the user input in accordance with the Rails naming conventions: if the suggested partial view name is bar, the generated name is _bar.html.erb or _bar.haml.

Example

BeforeAfter
View foo.html.erb:
/help/img/idea/2016.3/ruby_extractPartial0.png

View foo.html.erb:

/help/img/idea/2016.3/ruby_extractPartial1.png

Partial view _bar.html.erb:

/help/img/idea/2016.3/ruby_extractPartial2.png

To extract partial

  1. Open a view in the editor.
  2. Select the desired fragment of valid code. For example, in case of HTML, your selection must contain matching opening and closing tags.
  3. On the main menu, or on the context menu of the selection, choose Refactor | Extract | Partial.
  4. In the Extract Partial dialog box, specify the desired partial view name without extension and the leading underscore, and click OK.

See Also

Last modified: 21 March 2017