2011-01-27 51 views
0

相關型號此:Rake on Rails 3 problemRake任務 - 配置沒有找到

我試圖複製耙子任務下軌2個工作,爲軌道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 

On Rails的2它正確緩存的資產,在軌道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' 

在stylesheet_link_tag我的定義看見:

def stylesheet_link_tag(*sources) 
     options = sources.extract_options!.stringify_keys 
     concat = options.delete("concat") 
     cache = concat || options.delete("cache") 
     recursive = options.delete("recursive") 

     if concat || (config.perform_caching && cache) 
      joined_stylesheet_name = (cache == true ? "all" : cache) + ".css" 
      joined_stylesheet_path = File.join(joined_stylesheet_name ...... 
      ..... .... 

我的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 

我的配置/環境/ development.rb:

****::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 

回答

0

我有同樣的問題,在這裏找到一個解決方案:http://railsforum.com/viewtopic.php?id=42282

只是前綴

stylesheet_link_tag 

javascript_include_tag 

ApplicationController.helpers. 

那麼你不應該甚至必須包括助手的ActionView。

+1

不,在耙子任務中仍不起作用 – CLod 2011-04-08 00:09:58