Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingTemplate upgrading to Rails 7 #727

Open
jhirn opened this issue Apr 18, 2022 · 1 comment
Open

MissingTemplate upgrading to Rails 7 #727

jhirn opened this issue Apr 18, 2022 · 1 comment

Comments

@jhirn
Copy link

jhirn commented Apr 18, 2022

Hello. I'm performing an upgrade from Rails 6 -> 7.0.2.3.

I think this is not the right way to do this, but we have an render block in the text that is getting a MissingTemplate error.

subject(:described_view) { render template: "notifications/slack/new_current_coverage_created.md.erb" }

I believe i'm up against some combination of not having the file extension in the file or template argument, using :formats and/or registering a custom handler but wanted to avoid rendering the template in a different way than it currently is so-as to keep the changeset as minimal as possible. Here is the stack trace I get with my code as-is.

     Failure/Error: subject(:described_view) { render template: "notifications/slack/new_current_coverage_created.md.erb" }
     
     ActionView::MissingTemplate:
       Missing template notifications/slack/new_current_coverage_created.md.erb with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :vtt, :png, :jpeg, :gif, :bmp, :tiff, :svg, :mpeg, :mp3, :ogg, :m4a, :webm, :mp4, :otf, :ttf, :woff, :woff2, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :gzip, :json, :xlsx], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby]}.
     
       Searched in:
         * "/Users/jhirn/src/tflow/core_api/app/views"
         * "/Users/jhirn/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/actionmailbox-7.0.2.3/app/views"
     
       Did you mean?  notifications/slack/new_current_coverage_created
                      notifications/slack/new_placement_event_created
                      notifications/slack/new_employer_created
                      notifications/slack/firm_quote_requested
                      notifications/slack/employer_disabled
                      rails/conductor/action_mailbox/inbound_emails/new
    

Here's an example handler I've done in an initializer which registers the handler, but does help with finding the template

Rails.application.config.to_prepare do
  class MarkdownTemplateHandler
    def call(template, source)
      markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)

      compiled_source = erb.call(template, source)

      markdown.render(compiled_source).inspect.html_safe
    end

    private

    def erb
      @erb ||= ActionView::Template.registered_template_handler(:erb)
    end
  end

  ActionView::Template.register_template_handler(:md, MarkdownTemplateHandler.new)
end

Any insights are appreciated.

@bopm
Copy link

bopm commented May 24, 2022

https://stackoverflow.com/a/71069848/511374 so you have to remove .md.erb from your partial reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants