Closed gkulasik closed 6 years ago
Hi . Gitter channel is a better place to ask questions like this - there is bunch of us there. Having said that - one approach is - you can explicitly call a cell - render it to html - and respond with html.
Have a good day !
Nick
On Dec 23, 2017, 20:31 -0600, Greg Kulasik notifications@github.com, wrote:
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| %>
<%= element.render :tab_name %> <% 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 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
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.
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!
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. :beers:
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.
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:
The relevant view:
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