spree / deface

Rails plugin that allows you to customize ERB views in a Rails application without editing the underlying view.
MIT License
520 stars 127 forks source link

Error if an helper method name matches a template name #191

Closed nanego closed 5 years ago

nanego commented 5 years ago

Hi I encounter an error with my Rails 5.2 app since this commit: https://github.com/spree/deface/commit/0761a26f722741ba67da121e38efd262fe12b3b9

We override a page which has this virtual path: layouts/base and we have an helper method which is named view_layouts_base_sidebar_hook_response (in the ApplicationHelper module).

As this helper method is a method of ActionView::Base, it matches this test: ActionView::Base.instance_methods.detect { |name| name =~ /#{args[:virtual_path].gsub(/[^a-z_]/, '_')}/ } and the application sees it as a compiled template.

We could at least restrict the regex to check string boundaries: /\b#{args[:virtual_path].gsub(/[^a-z_]/, '_')}\b/

But the error could still happen if we had, for instance, a layouts/base path and a layouts_base helper method.

It seems that, in Rails 6, CompiledTemplates will be available in ActionDispatch::DebugView (if I understand well this commit from @tenderlove: https://github.com/rails/rails/commit/f9bea6304dfba902b1937b3bc29b1ebc2f67e55b). If it's the case, it may help.

Thank you for your work.

damianlegawiec commented 5 years ago

Hi @nanego we've released 1.5.0 fixing this issue