Ruby on rails rails 3上的Rake任务-未找到配置

Ruby on rails rails 3上的Rake任务-未找到配置,ruby-on-rails,rake,task,Ruby On Rails,Rake,Task,与此相关: 我正在尝试将rails 2下的rake任务复制到rails 3应用程序中 rake任务如下所示: namespace :cached_assets do desc "Regenerate aggregate/cached files" task :regenerate => :environment do include ActionView::Helpers::TagHelper include ActionView::Helpers::UrlHelp

与此相关:

我正在尝试将rails 2下的rake任务复制到rails 3应用程序中

rake任务如下所示:

namespace :cached_assets do
  desc "Regenerate aggregate/cached files"
  task :regenerate => :environment do
    include ActionView::Helpers::TagHelper
    include ActionView::Helpers::UrlHelper
    include ActionView::Helpers::AssetTagHelper
    stylesheet_link_tag :all, :cache => CACHE_CSS_JS
    javascript_include_tag  "a.js", "b.js", 
              "c.js", :defaults, :cache => CACHE_CSS_JS
    javascript_include_tag  "q.js", "w.js", 
               "e.js", :cache => 'abc'
  end
end
在Rails 2上,它会正确缓存资产,在Rails 3上,我有以下错误:

rake cached_assets:regenerate --trace
(in /var/www/apps/****)
** Invoke cached_assets:regenerate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute cached_assets:regenerate
rake aborted!
undefined local variable or method `config' for #<Object:0xa86290>
/opt/ruby-enterprise/lib/ruby/gems/1.8/gems/actionpack-3.0.3/lib/action_view/helpers/asset_tag_helper.rb:498:in `stylesheet_link_tag'
/var/www/apps/****/lib/tasks/cached_assets.rake:10
/opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/opt/ruby-enterprise/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
My config/application.rb:

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)

module ****
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Custom directories with classes and modules you want to be autoloadable.
    # config.autoload_paths += %W(#{config.root}/extras)

    # Only load the plugins named here, in the order given (default is alphabetical).
    # :all can be used as a placeholder for all plugins not explicitly named.
    # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

    # Activate observers that should always be running.
    # config.active_record.observers = :cacher, :garbage_collector, :forum_observer

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de

    # JavaScript files you want as :defaults (application.js is always included).
    # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)

    # Configure the default encoding used in templates for Ruby 1.9.
    config.encoding = "utf-8"

    # Configure sensitive parameters which will be filtered from the log file.
    config.filter_parameters += [:password]

    config.time_zone = 'UTC'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
    # config.i18n.default_locale = :de

    # use memcache
    config.cache_store = :mem_cache_store, 'localhost:11211', { :namespace => 'nar_' }

    config.after_initialize do
      require 'lib/core_extensions.rb'
    end

  end
end

我也遇到了同样的问题,并在这里找到了解决方案:

只是前缀

stylesheet_link_tag

那么您甚至不必包含ActionView助手

****::Application.configure do


  # Settings specified here will take precedence over those in config/environment.rb

# In the development environment your application's code is reloaded on
# every request.  This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_view.debug_rjs                         = true
config.action_controller.perform_caching             = false

# EMAIL -> see also initializers/emailer_initializers.rb and /config/email.yml !!!!!!!!!!!!
EMAIL_ENABLED = false
config.action_mailer.raise_delivery_errors = true
MAIL_FROM = '****'
RCPT_TO_DEV = '****'

ENV['RAILS_ASSET_ID'] = '100'

PRODUCTION_DOMAIN_NAME = "*****"

#CSS CACHING
CACHE_CSS_JS = false


  # Print deprecation notices to the Rails logger
  config.active_support.deprecation = :log

  # Only use best-standards-support built into browsers
  config.action_dispatch.best_standards_support = :builtin
end
stylesheet_link_tag
javascript_include_tag
ApplicationController.helpers.