Defect #11151

Functions from helper modules for plugin not accessible

Added by Vitaly Klimov over 10 years ago. Updated 11 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:


Category:Plugin API
Target version:-
Resolution:Invalid Affected version:2.0.1


It seems that files under plugins/plugin_name/helpers ignored by Rails completely.

To check this, just create some SettingsHelper module in file names settings_helper.rb in some plugin folder:

module SettingsHelper
  def get_text
    "Plugin description" 

Next, create file in app/views/settings/ named _some_plugin_settings.html.erb with following content:

<fieldset class="box tabular">
    <%= get_text %>

Then add settings property to plugin init.rb file:

settings(:partial => 'settings/some_plugin_settings')

Now, when you try to configure plugin you will get undefined method (get_text) error.


#1 Updated by Vitaly Klimov over 10 years ago

Update: same applies for files in controllers folder as well if they are differ from plugin controllers.

For example, you are not able to add some functions to, sys, messages_controller.rb by simply putting file with function in app/controllers/messages_controller.rb

#2 Updated by Jean-Philippe Lang over 10 years ago

  • Status changed from New to Closed
  • Resolution set to Invalid

This is not supposed to work. Your helpers will be loaded automatically for your plugin controllers. But if you want to extend the core helpers, you'll have to get your own modules included by the core helpers, eg.:

module MyHelper
  def my_custom_method
    # do something

require 'settings_helper'
SettingsHelper.send :include, MyHelper

#3 Updated by Vitaly Klimov over 10 years ago

Thanks. I know about this way of extending helpers. But method described by me above was perfectly normal while plugins were in vendor/plugins folder. I guess there should be some note about it somewhere in docs.

Also available in: Atom PDF