Project

General

Profile

Actions

Defect #11151

closed

Functions from helper modules for plugin not accessible

Added by Vitaly Klimov over 12 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Plugin API
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Invalid
Affected version:

Description

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" 
  end
end

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

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

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.

Actions #1

Updated by Vitaly Klimov over 12 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

Actions #2

Updated by Jean-Philippe Lang over 12 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
  end
end

require 'settings_helper'
SettingsHelper.send :include, MyHelper
Actions #3

Updated by Vitaly Klimov over 12 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.

Actions

Also available in: Atom PDF