Integración de apotomo con páginas de refinycms.
-
15-11-2019 - |
Pregunta
Me gustaría extender los PagesController de refinycms para usar algunos widgets de Apotomo en nuestro proyecto.
Podría potencialmente hacer una "anulación" de los PagesController, que lo copia en mi proyecto, pero estoy usando otro motor que extiende el Controlador de Páginas (modificando los métodos de muestra y el hogar con un enfoque de mono / mono) I 'D más bien evitar eso.
Mi enfoque inicial fue algo así:
en config / application.rb:
config.before_initialize do
require 'pages_controller_extensions'
end
config.to_prepare do
PagesController.send :include, Refspike::Extensions
end
en Pages_Controller_Extensions:
module Refspike
module Extensions
class << PagesController
include Apotomo::Rails::ControllerMethods
has_widgets do |root|
root << widget(:map)
end
end
end
end
Desafortunadamente, esto sopla en la línea "Helper ActionViewMethods" en los métodos de controlador de Apotomo.Agregar Incluir Apotomo :: Rails :: ActionViewMethods no ayudó.
Supongo que estoy obteniendo un detalle básico sobre la gestión de la dependencia de los rieles o quizás las clases abiertas de Ruby están mal.¿Existe un enfoque alternativo, o algo simple que esté pasando por alto?
Solución 2
Here's the solution. Remove the before_initialize stuff; there's simply no need for this to be in a module. In application.rb, do:
config.to_prepare do
::PagesController.send :include, Apotomo::Rails::ControllerMethods
::PagesController.has_widgets do |root|
root << widget(:map)
end
end
Then, override refinery's shared/_content_page.html.erb to include:
<%=render_widget :map %>
Done and done.
What was wrong before? Well, calling ::PagesController.send :include, Refspike::Extensions
means that I'm actually "almost" in the scope of the class I'm trying to modify, but not quite. So, reopening the class is unnecessary, for one thing. But an ActiveSupport method, class_inheritable_array being called by apotomo, apparently isn't discoverable in my module scope, either, so I can't get away with doing something like:
#doesn't work
module Refspike
module Extensions
include Apotomo::Rails::ControllerMethods
has_widgets do |root|
root << widget(:map)
end
end
end
Fortunately, the 4 lines of code in the application.rb are a simpler solution, and that does the trick for me.
Otros consejos
Is PagesController a derived ActionController?