erb-to-view-model

Migrate ERB templates to precomputed Ruby ViewModels with explicit init parameters.

Updated Feb 27, 2026
One-click install
npx skills add https://github.com/dailydm/skills --skill erb-to-view-model
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: erb-to-view-model
Source: https://github.com/dailydm/skills/tree/main/erb-to-view-model
Command: npx skills add https://github.com/dailydm/skills --skill erb-to-view-model

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

ERB templates often mix presentation with business logic or rely on instance variables and helpers, making maintenance painful. This Skill guides migrating ERB templates to precomputed Ruby ViewModels that read only from explicit data, improving testability and separation of concerns.

Core Features & Use Cases

  • Precompute values in a dedicated ViewModel under app/view_models/, replacing @variables and helpers with view_model attributes.
  • Thin controllers that pass a single view_model to views and delegate logic to the ViewModel.
  • Bottom-up migration starting from deepest partials and moving upward, ensuring complete render-tree coverage.

Quick Start

Create a new or updated ViewModel using self.init(params) and render the view with locals: { view_model: @view_model }.

Frequently Asked Questions about erb-to-view-model

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I remove business logic from ERB templates in Rails?

Migrate ERB templates by precomputing values in a dedicated Ruby ViewModel to remove direct model access from views. This replaces instance variables and helpers with explicit view_model attributes, improving testability and separation of concerns.

What is a precomputed ViewModel in Ruby on Rails?

A precomputed ViewModel is a Ruby object under app/view_models/ that calculates values upfront via self.init(params). It replaces direct model access and helpers in views with explicit attributes, ensuring views read only from prepared data.

How do I migrate Rails views to ViewModels step by step?

Migrate ERB templates bottom-up by starting from the deepest partials and moving upward through the render tree. Update controllers to pass a single view_model as a local, delegating all logic to the precomputed ViewModel attributes.

Can I use a ViewModel with current_user logic in Rails views?

Yes, the migration process replaces current_user logic and instance variables by precomputing those values into ViewModel attributes. The controller passes the precomputed view_model to the view, removing direct access to current_user from the template.

Does migrating to ViewModels require thin controllers in Rails?

Yes, migrating to precomputed ViewModels requires thin controllers that pass a single view_model to views. The controller delegates business logic to the ViewModel, satisfying constraints for explicit initialization parameters and separation of concerns.

What is the best way to handle Rails view helpers during migration?

Replace Rails view helpers by precomputing their output into ViewModel attributes during migration. This moves the helper logic out of the ERB template and into the Ruby ViewModel, ensuring the view only reads from explicit data.