从另一个调用模块的方法

时间:2015-12-24 07:18:31

标签: ruby-on-rails ruby module

我已经定义了一个类user_controller,它从lib(start_mail)中的模块调用方法lib/mail_start.rb。在同一个班级User, 我正在调用lib中定义的check_mail模块中存在的方法mail_check - lib/process/mail_check.rb

问题来自check_mail(lib文件中的模块中存在的方法),我必须启动邮件,因此我必须调用start_mail(同一lib文件中另一个模块中存在的方法)。要在模块mail_start.rb中加入mail_check.rb,我在模块include MailStart中使用了require 'lib/mail_start'MailCheck

但我收到的错误为undefine method in module MailCheck

3 个答案:

答案 0 :(得分:0)

我给你的解决方案就是我的假设。     的 user_controller.rb

static NSString *_uuid = nil;
+ (NSString *)UUID
{
    if (_uuid != nil)
        return _uuid;

    // Build a query
    CFMutableDictionaryRef query = CreateKeychainQueryDictionary();

    // See if the attribute exists
    CFTypeRef attributeResult = NULL;
    OSStatus status = SecItemCopyMatching(query, (CFTypeRef *)&attributeResult);
    if (attributeResult != NULL)
        CFRelease(attributeResult);

    if (status != noErr) 
    {
        CFRelease(query);
        if (status == errSecItemNotFound) // If there's no entry, store one
        {
            return [[self class] storeUUID:NO];
        }
        else // Any other error, log it and return nil
        {
            NSLog(@"BPXLUUIDHandler Unhandled Keychain Error %ld", status);
            return nil;
        }
    }

模块将是require 'mail_start' # You need to re-write your code class UsersController < ApplicationController p include MailCheck def index end end

lib/mail_start.rb

也适合你!

答案 1 :(得分:0)

config/application.rb

中自动加载模块父目录的路径

试试这个

module YourAppNAme
  class Application < Rails::Application
    config.autoload_paths += %W(#{config.root}/lib/process)
  end
end

然后在include

user_controller
include MailCheck 

我希望这会有所帮助。

答案 2 :(得分:0)

尝试在helpers / mail_check中定义check_mail,然后在user_controller中包含MailCheck。