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

Element views not rendering from Solidus #1626

Closed
gabrielrios opened this issue Sep 25, 2019 · 8 comments · Fixed by AlchemyCMS/alchemy-solidus#53
Closed

Element views not rendering from Solidus #1626

gabrielrios opened this issue Sep 25, 2019 · 8 comments · Fixed by AlchemyCMS/alchemy-solidus#53

Comments

@gabrielrios
Copy link

gabrielrios commented Sep 25, 2019

Steps to reproduce

If you try to render a Element from inside a solidus page

  <%= render_elements from_page: 'header' %>

The element won't render, only showing <!-- Missing view for element -->.
It tries to render app/views/spree/alchemy/elements/element_view instead of app/views/alchemy/elements/element_view

This worked fine on Alchemy 4.1, I'm guessing this is related to render_elements changes on #1553 and #1554

System configuration

  • Alchemy Version: 4.3.0
  • Rails Version: 5.2.3
@tvdeyen
Copy link
Member

tvdeyen commented Sep 25, 2019

Very interesting. Thanks for reporting. This seems to be a namespacing issue. What controller scope are you running this views code in?

@gabrielrios
Copy link
Author

gabrielrios commented Sep 25, 2019

Spree. This code is on my "spree/layouts/spree_application.html.erb". The controller is Spree::ProductsController

@DennisNissen
Copy link

DennisNissen commented Oct 16, 2019

Rails will by default prepend the controller namespace to the partials path. If you render your Elements inside a view rendered by a namespaced controller rails uses the to_partial_path method of the Alchemy::Element-Model and the namespace of the controller to resolve the partial path.

The only way to get around this maybe to MonkeyPatch Alchemy::ElementsHelper to disable controller namespace prepending.

module Alchemy::ElementsHelper
  def disable_controller_naymspace_in_partial_path
    ActionView::Base.prefix_partial_path_with_controller_namespace = false
  end

  def enable_controller_naymspace_in_partial_path
    ActionView::Base.prefix_partial_path_with_controller_namespace = true
  end

  alias_method :old_render_element, :render_element

  def render_element(*args)
    disable_controller_naymspace_in_partial_path
    content = old_render_element(*args)
    enable_controller_naymspace_in_partial_path
    content
  end
end

@tvdeyen this breaks every usage of element views in plugin engines (if they use isolate_namespace) - i don't know the exact implications of disabling the prefix_partial_path_with_controller_namespace to other parts of alchemy, but maybe you can consider disabling it in Alchemy::ElementsHelper.render_element when rendering the element views.

@tvdeyen
Copy link
Member

tvdeyen commented Nov 17, 2019

@DennisNissen thanks for the detailed report. Maybe it helps to prefix the path from to_partial_path with a leading slash? Hopefully this tells Rails to use an "absolute" and not "relative" path. I really would like to not have to do the proposal. Rather I would like to discuss with Rails core team to make this optional on a per render basis. This can't just only be us who have issues with this debatable "feature".

Can you please try to override to_partial_path in app/models/alchemy/element.rb and report if this fixes your issues? @gabrielrios

@DennisNissen
Copy link

I think that was the first thing i tried, but it did not work.

I would be sufficient if to_partial_path could be set to "absolut" or "relative" - but i think that might not be the best place to enable/disable a controller to prepend his namespace. I'm curious what the rails core team come up with concerning this issue :).

@tvdeyen
Copy link
Member

tvdeyen commented Nov 18, 2019

Reading this over and over again and I think this is odd behavior from Rails.

Alchemy itself is an isolated and name spaced engine. Since we explicitly add the alchemy namespace in the elements to_partial_path and we render_elements in the Alchemy controller namespace, we should actually get app/views/alchemy/alchemy/elements as element partial path, but we do not.

Either Rails is magically removing duplicated namespaces or we miss something here.

I think we should disable ActionView::Base.prefix_partial_path_with_controller_namespace in the alchemy-solidus gem in the alchemy_in_solidus module, as Alchemy does not need this setting to work (we set the namespace in Alchemy::Element#to_partial_path and Solidus does not either. All partial paths are explicitely setting spree as well.

This action view feature is very confusing.

tvdeyen added a commit to tvdeyen/alchemy-solidus that referenced this issue Nov 18, 2019
If you want to render alchemy elements in a Solidus controller
namespace, we need to disable prefixing of controller path to partial
paths, or we get an extra `spree` namespace for the element partial
paths and the elements wont render.

Closes AlchemyCMS/alchemy_cms#1626
@tvdeyen
Copy link
Member

tvdeyen commented Nov 18, 2019

@gabrielrios @DennisNissen created AlchemyCMS/alchemy-solidus#53

Could you try this in your apps and report if this fixes your issue and does not introduce new ones?

@jrieger
Copy link
Contributor

jrieger commented Nov 18, 2019

@tvdeyen I can confirm this works.

tvdeyen added a commit to tvdeyen/alchemy-solidus that referenced this issue Dec 13, 2019
If you want to render alchemy elements in a Solidus controller
namespace, we need to disable prefixing of controller path to partial
paths, or we get an extra `spree` namespace for the element partial
paths and the elements wont render.

Closes AlchemyCMS/alchemy_cms#1626
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants