Link Search Menu Expand Document

Frequently asked questions

Can I use other templating languages besides ERB?

Yes. ViewComponent is tested against ERB, Haml, and Slim, but it should support most Rails template handlers.

Isn’t this just like X library?

ViewComponent is far from a novel idea! Popular implementations of view components in Ruby include, but are not limited to:

Can I use validations with ViewComponents?

ViewComponent does not include support for validations. However, it can be added by using ActiveModel::Validations:

class ExampleComponent < ViewComponent::Base
  include ActiveModel::Validations

  # Requires that a content block be passed to the component
  validate :content, presence: true

  def before_render
    validate!
  end
end

Note: Using validations in this manner can lead to runtime exceptions. Use them wisely.