无法从Rails引擎中的应用程序控制器访问我的帮助程序中的变量

时间:2014-09-30 17:32:54

标签: ruby-on-rails-3 ruby-on-rails-4 gem rails-engines

我创建了一个扩展Rails引擎的gem。我正在使用Rails 4.一切正常,除了我无法从帮助程序访问应用程序控制器中的实例变量。这是我的代码......我做错了什么?

应用/控制器/ application_controller.rb

   class ApplicationController < ActionController::Base

    protect_from_forgery with: :exception

    def get_context
    @variable  = "variable"
    end
    end

应用/助手/ evaluate_helper.rb

      module EvaluateHelper

      def app_name
      @variable   #=> nothing here
      end
      end

LIB /评估/ version.rb

      require "rails"
      require "evaluate/version"

     module Evaluate
      VERSION = "0.0.1"

     class Engine < ::Rails::Engine
      end
    end

evaluate.gemspec

    lib = File.expand_path('../lib', __FILE__)
    $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
    require 'evaluate/version'

    Gem::Specification.new do |spec|
    spec.name          = "evaluate"
    spec.version       = Evaluate::VERSION
    spec.authors       = ["My name"]
    spec.email         = ["myemail"]
    spec.summary       = %q{Evaluation}
    spec.description   = %q{Evaluation and analysis of application usage.}
    spec.homepage      = ""
    spec.license       = "MIT"

    spec.files         = `git ls-files -z`.split("\x0")
    spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
    spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
    spec.require_paths = ["lib"]

    spec.add_development_dependency "rails", ">= 3.1"
    spec.add_development_dependency "bundler", "~> 1.6"
    spec.add_development_dependency "rake"
    spec.add_development_dependency "browser"
    end

0 个答案:

没有答案