forem/forem · error · StandardError
Lead form not found
Error message
Lead form not found
What it means
Forem's {% org_lead_form ID %} Liquid tag embeds an organization lead-capture form. During Liquid parsing it loads the record with OrganizationLeadForm.find_by(id:) and raises immediately when the lookup returns nil, before the active? and ownership checks run. Because Liquid tags initialize while markdown is processed, this surfaces as a liquid tag validation error when the containing page markdown is saved, previewed, or rendered.
Source
Thrown at app/liquid_tags/org_lead_form_tag.rb:9
class OrgLeadFormTag < LiquidTagBase
PARTIAL = "liquids/org_lead_form".freeze
VALID_CONTEXTS = %w[Organization].freeze
def initialize(_tag_name, input, _parse_context)
super
@form_id = parse_form_id(input)
@form = OrganizationLeadForm.find_by(id: @form_id)
raise StandardError, I18n.t("liquid_tags.org_lead_form_tag.not_found") unless @form
raise StandardError, I18n.t("liquid_tags.org_lead_form_tag.inactive") unless @form.active?
source = parse_context.partial_options[:source]
unless @form.organization_id == source.id
raise StandardError, I18n.t("liquid_tags.org_lead_form_tag.wrong_organization")
end
end
def render(_context)
ApplicationController.render(
partial: PARTIAL,
locals: { form: @form },
)
end
private
def parse_form_id(input)View on GitHub (pinned to f354c376a7)
Solutions
- Run OrganizationLeadForm.find_by(id: 123) in a rails console against the same database the markdown renders with; if it returns nil, the ID is wrong for this environment
- Get the correct ID from the owning organization's lead form settings and update the tag to {% org_lead_form <real_id> %}
- If the form was deleted, create a new lead form in that organization and replace the old ID in every page that embedded it
- In tests, build the form with create(:organization_lead_form, organization: org) and interpolate form.id into the markdown instead of hard-coding
Example fix
// before
{% org_lead_form 999 %} <!-- no form 999 in this database -->
// after
{% org_lead_form 42 %} <!-- existing form in this org --> Defensive patterns
Strategy: validation
Validate before calling
form = OrganizationLeadForm.find_by(id: form_id)
fail 'form not found' unless form
fail 'form inactive' unless form.active?
fail 'wrong organization' unless form.organization_id == org.id
# only now embed {% org_lead_form #{form_id} %} Try / catch
begin
Liquid::Template.parse(body_markdown)
rescue StandardError => e
# e.message is already the localized user-facing text
errors.add(:body_markdown, "Liquid tag error: #{e.message}")
end Prevention
- Resolve the form ID in the target environment's console before embedding
- Grep stored markdown for 'org_lead_form' before deleting or renumbering lead forms
- In specs, factory-create the lead form and interpolate its id
When it happens
Trigger: Embedding {% org_lead_form 123 %} where no organization_lead_forms row with id=123 exists in the current database: the form was deleted, the ID is mistyped, or the ID was copied from another environment (staging ID used on production).
Common situations: Org page markdown copied between environments whose databases hold different form IDs; an org admin deletes a lead form while pages still embed it; test suites hard-coding form IDs instead of using factories.
Related errors
- This lead form is no longer active
- Invalid organization slug
- Invalid organization slug
- Invalid organization slug
- This lead form does not belong to this organization.
AI-assisted analysis of forem/forem@f354c376a7 (2026-08-21).
Data as JSON: /api/errors/74b6f43d952c77a5.
Report an issue: GitHub.