madebymany / sir-trevor-rails

Rails gem for Sir Trevor integration.
MIT License
149 stars 50 forks source link

ActionView::MissingTemplate with namespaced controller in Rails 6 #61

Open otagi opened 4 years ago

otagi commented 4 years ago

When a controller with a namespace is used to show a Sir Trevor attribute, Rails will prepend the block partial path with that namespace, causing an ActionView::MissingTemplate exception.

It looks like SirTrevorRails::ViewResolver#find_templates should correct the path, but that method is never called by Rails 6.0.3.2.

Example:

# app/models/blog/post.rb
class Blog::Post < ApplicationRecord
  sir_trevor_content :content
end

# app/controllers/blog/posts_controller.rb
class Blog::PostsController < ApplicationController
  def show
    @blog_post = Blog::Post.find(params[:id])
  end
end

# app/views/blog/posts/show.html.erb
<%= render @blog_post.content %>

Error:

ActionView::MissingTemplate in Blog::Posts#show

Showing [root]/app/views/blog/posts/show.html.erb where line #1 raised:

Missing partial blog/sir_trevor/blocks/_text_block with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}. Searched in:
  * "[root]/app/views"
  * …