Class: RuboCop::Cop::Rails::RenderInline

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rails/render_inline.rb

Overview

Looks for inline rendering within controller actions.

Examples:

# bad
class ProductsController < ApplicationController
  def index
    render inline: "<% products.each do |p| %><p><%= p.name %></p><% end %>", type: :erb
  end
end

# good
# app/views/products/index.html.erb
# <% products.each do |p| %>
#   <p><%= p.name %></p>
# <% end %>

class ProductsController < ApplicationController
  def index
  end
end

Constant Summary collapse

MSG =
'Prefer using a template over inline rendering.'
RESTRICT_ON_SEND =
%i[render].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



35
36
37
# File 'lib/rubocop/cop/rails/render_inline.rb', line 35

def on_send(node)
  add_offense(node) if render_with_inline_option?(node)
end