Skip to content

Instantly share code, notes, and snippets.

View ahmad19's full-sized avatar
:electron:

Ahmad hamza ahmad19

:electron:
View GitHub Profile
@ahmad19
ahmad19 / _form.html.erb
Last active November 1, 2024 17:28
Render model validation errors inline by adding a simple presenter class
<%= form_with(model: post) do |form| %>
<% error_handler = ::InlineErrorHandler.new(post, self) %> # Initialize the error handler presenter here, or consider doing this in the controller
<div>
<%= form.label :title, style: "display: block" %>
<%= form.text_field :title %>
<%= error_handler.error_message_for(:title) %> # Display inline error for the title field here
</div>
<div>
<%= form.label :body, style: "display: block" %>