Using Rails 4 engine/plugin helpers across your entire app

Sometimes you need your rails engine/plugins helpers to work across the host app. An example of this is my Gem Paginas. I provide helper methods to generate menu links, since the menus can exist outside the scope of my gem, it was necessary to include these methods in the host app.

It is quite simple to do so, using the Paginas Gem as an example, all you need to do is add this to your host app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
  # your code
  helper Paginas::ApplicationHelper

  # your other code

Replace Pagians with your Engine/Plugin name, and that's it! plain and simple

In Development Environment, the engines/plugins are not automatically reloaded every time there are changes to your files. This can cause problems with these helpers specially if they use the engine's/plugin's associations.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.