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

Using Cells with Rails engine that has html.erb partials not being picked up #460

Closed
gkulasik opened this issue Dec 24, 2017 · 5 comments
Closed

Comments

@gkulasik
Copy link

Hi,

I've really enjoyed playing with Cells and wanted to incorporate in a new project I am working on!

I am using Alchemy CMS to support the content side of things and am building 'elements,' basically blocks of code that seem to really ideologically fit in with the Cells approach.

While building my first element in Cells I've run into a problem where the Alchemy Engine is trying to render a partial but Cells is unable to find it. It is looking in the right directory but only looking for '.erb' files not '.html.erb'.

The relevant part of the Cell:

require "cell/partial"
class Element::TabItemCell < Element::ElementCell
  include Alchemy::ElementsHelper
  include Alchemy::ElementsBlockHelper
  include Partial

  self.view_paths = ["app/cells", "app/views", "#{Alchemy::Engine.root}/app/views"]
end

The relevant view:

<%= element_view_for(child, tag: false) do |element| %>
  <li class="<%= link_classes %>" id="<%= link_id %>">
    <a href="<%= href %>" data-toggle="tab" aria-selected="<%= is_active? %>">
      <%= element.render :tab_name %>
    </a>
  </li>
<% end %>

Error message:
Template missing: view: _essence_text_view.erb prefixes: ["app/cells/alchemy/essences", "app/views/alchemy/essences", "/Users/gkulasik/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/bundler/gems/alchemy_cms-0cb6cc49efb5/app/views/alchemy/essences"]

Basically, 'element.render' eventually tries to render a partial for that particular element (or element component called 'essence'). The file is located at '/Users/gkulasik/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/bundler/gems/alchemy_cms-0cb6cc49efb5/app/views/alchemy/essences/_essence_text_view.html.erb' which it renders correctly in regular Rails views or in helpers. I've scanned the documentation and have seen the components on adding in Rails Engines. Those docs helped solve some of the issues but I am still stumped on how to get Cells to look for both .erb and .html.erb files. I did try adding 'formats: [:html]' to the render calls but no dice.

Any help is appreciated!

Greg

@konung
Copy link

konung commented Dec 24, 2017 via email

@gkulasik
Copy link
Author

Thanks for the suggestion! I'll move my question over to Gitter.

Calling the cell won't work - Cells throws that exception because it cannot find the partial so if I call the cell I hit the exception before it is rendered. It's possible I am not understanding your solution. I am still pretty new to Cells.

@apotonick apotonick reopened this Dec 24, 2017
@apotonick
Copy link
Member

Hi Greg,

rendering partials in a cell is a hack, and we only support it so "application partials" can be rendered by the developers of the cell calling render partial: .... This is to help people move from monolithic view architectures to cells.

Having that said, I'm afraid using your Alchemy helpers in the cell is the wrong approach. We could make the rendering of the partial work, but then, other dependencies might be missing, and so on. The problem is that normal Rails helpers are designed without any interfaces and do access global state, use capture etc. and unfortunately, most gems build on top of that crap lack of API, which I personally do not understand, but, yeah.

To get that partial rendering working, you can hack the cell's render method the way we do it in the partial.rb file - let me know if that works or not!

@apotonick
Copy link
Member

Here's the file you're interested in: https://github.com/trailblazer/cells/blob/master/lib/cell/partial.rb#L4

Once you found a way to make it work, please post it here so we can discuss a canonical solution. 🍻

@gkulasik
Copy link
Author

Thanks for the tips, @apotonick!

I've looked into this more over the last few days. I think you are right about the issues with partials and helpers. Alchemy uses helpers for everything, including capture. This results in missing dependency after dependency. I've decided to just use the 'standard' Rails approach to get through this project :/.

Given the amount of work needed to make this work via monkey patching, I think a better solution would be to enhance Alchemy to use Cells rather than helpers. A project for another day :).

Thanks for the help! Will close now since this is not an issue with Cells but more an external gem limitation.

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

3 participants