apotomo
apotomo copied to clipboard
Apotomo doesn't look for views in Engines
I've got a problem when using Apotomo in conjunction with Engines:
Missing template usage/display with {:handlers=>[:erb, :builder],
:formats=>[:html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom,
:yaml, :multipart_form, :url_encoded_form, :json, :docx, :pptx,
:xlsx], :locale=>[:"pt-BR", :"pt-BR"]}. Searched in:
* "/Users/lunks/Code/tarifador/app/widgets"
Looks to me that Apotomo/Cells doesn't respect engines when looking for
views. app/widgets/usage_widget.rb
works if in an Engine, though.
PS: This was already posted here, but this looks like an issue, so I'm posting it here. Sorry for duplcating stuff around, Nick. ;)
Yes, the same problem! It does not search widget view in an engine module path (app/widgets/my_engine/my_widget/).
Try updating cells
to >= 3.8.1!
I can't make this work either. Exactly how would this work for apotomo? Do I need to define a app/cells
folder or app/widgets
folder in my host engine? What if it is just normal partials?
In my case I want to call gmaps4rails
helper which calls a partial in app/views/gmaps4rails/_gmaps4rails
but looks like this is IMPOSSIBLE from within a widget!?
Would be nice if at least specifying :partial on the render, it would fallback to classic Rails partial behavior.
Please help fix this ASAP. Thanks!
Been trying this cruel hack... just for the hell of it, but no success!
module Apotomo
class Widget < Cell::Rails
DEFAULT_VIEW_PATHS = [File.join('app', 'widgets'), File.join('app', 'cells'), File.join('app', 'views')]
then copied /gmaps4rails/_gmaps4rails_libs.html.erb
into app/views
of my Rails application
Also tried renaming the partial to a "normal" view, i.e no underscore prefix:
Missing partial /gmaps4rails/gmaps4rails_libs with {:locale=>[:da], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in:
* "/Users/kmandrup/private/repos/company/friendly_view/app/widgets"
* "/Users/kmandrup/private/repos/company/friendly_view/app/cells"
* "/Users/kmandrup/private/repos/company/friendly_view/app/views"
What the fuck!?
Crazy stuff! The only way I could make it work was to copy the partial into the current widget view container to make another widget view for the widget. There MUST be another way?
= render view: 'gmaps4rails_libs', :locals => { :js_dependencies => @js_dependencies}
Damn!
Another curious thing is that it seems like my methods in ActionController
and ApplicationHelper
are not available in my widget views. How would I make them available to my base widget? Some libraries introduce view helper methods in these places and would be nice to be able to use those...
@kristianmandrup: perhaps you should first gather your full intel, and then pour it into a single, witty, comment. This is annoying...
Imo; not being able to access all the views you mentioned (incl. helpers) is a very good design decision.
I'm sorry. It is just coz I spent 2 frustrating hours deep diving into cells and apotomo in order to figure out how to solve this...
It wasn't clear from the documentation that it wasn't possible or specifically designed not to allow it. I think you are right that it could be a good design situation to keep it separate from the views functionality, now that I have found my ground again ;)
On another note: is it possible to mount widgets with views from other engines, similar to how it is possible in cells?
You can try creating initializer file in your application with code:
Rails.application.config.after_initialize do
Apotomo::Widget.append_view_path YourEngine::Engine.root + 'app/widgets'
end
This works for me.
If you are trying to render a global partial, @kristianmandrup here is what you have to do: https://github.com/apotonick/cells#rendering-global-partials
Also, check out the test: https://github.com/apotonick/cells/blob/master/test/rails/view_test.rb#L22
This has been working ever since, BTW ;-)
Thanks a lot. I will look into it. Very exciting!
So are you saying that doing append_view_path "app/views"
from within an apotomo widget works the same as a cell?
Would be awesome! Thanks!
I understand it should be used with care for sure since it breaks the widget encapsulation. In fact I don't really like that gmaps4rails has those partials. They should instead be available as view helpers IMO. I guess you still have access to anything added to ActionBase::View
from within an apotomo widget view?
Would be nice if the docs made all this a little more clear.
Thanks!
On Fri, Sep 14, 2012 at 12:53 PM, Kristian Mandrup <[email protected]
wrote:
So are you saying that doing append_view_path "app/views" from within an apotomo widget works the same as a cell? Would be awesome! Thanks!
Absolutely, a widget is just a cell on cocaine.
I understand it should be used with care for sure since it breaks the widget encapsulation. In fact I don't really like that gmaps4rails has those partials. They should instead be available as view helpers IMO. I guess you still have access to anything added to ActionBase::View from within an apotomo widget view?
No- gmap4rails should use a cell instead of a partial.
Would be nice if the docs made all this a little more clear.
You're welcome to contribute ;-)
Thanks!
— Reply to this email directly or view it on GitHubhttps://github.com/apotonick/apotomo/issues/54#issuecomment-8557791.
So to mount the widgets of an engine, I could add a config/initializers/apotopo.rb
file in the engine with the following:
Rails.application.config.after_initialize do
Apotomo::Widget.append_view_path My::Engine.root + 'app/widgets'
end
This would in turn add this engines' view path to the Rails app hosting this engine. Sweet :) Would be nice if this approach was described in the README or wiki ;)
In my own "version" of apotomo, I've added an engine_setup
generator, which generates an apotomo.rb
initializer as suggested by @jaaarzyna