lundi 16 mars 2015

Rails: trouble including modules via a plugin

I'm trying to create a rails plugin and the problem I'm facing is that the app won't include my modules when migrating the plugin.


Here's what I have so far:

1. A file lib/patch/settings_helper_patch.rb with extension code

2. An init.rb file with require_dependency 'patch/settings_helper_patch'

3. Some code in settings_helper_patch.rb which is as follows:



module ValidateIssuePatch
module Patch
module SettingsHelperPatch
def self.included(base)
base.send(:include, InstanceMethods)
end

module InstanceMethods
def issue_options
#some code here
end
end
end
end
end

unless SettingsHelper.included_modules.include?(ValidateIssuePatch::Patch::SettingsHelperPatch)
SettingsHelper.send(:include, ValidateIssuePatch::Patch::SettingsHelperPatch)
end


After I migrate the plugin, I wish to use the issue_options method, but I get undefined local variable or method error.


If I run SettingsHelper.included_modules.include?(ValidateIssuePatch::Patch::SettingsHelperPatch) from the console, I get uninitialized constant Patch::SettingsHelperPatch.

However, if I call ValidateIssuePatch from the console, I get => ValidateIssuePatch in response.


Can anyone tell me what is the magic I'm missing here?


Aucun commentaire:

Enregistrer un commentaire