簡體   English   中英

為什么無法通過rake資產進行預編譯

[英]Why rake assets precompile doesn't work

我正在使用Letsrate寶石
rake assets: precompile raises以下內容。
我想在heroku上部署並引發相同的錯誤。

    /home/sunloverz/.rvm/rubies/ruby-1.9.3-p385/bin/ruby /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
    rake aborted!
    undefined method `rate_path' for #<Module:0x9d31338>
      (in /home/sunloverz/RubymineProjects/socialnews/app/assets/javascripts/letsrate.js.erb)
    /home/sunloverz/RubymineProjects/socialnews/app/assets/javascripts/letsrate.js.erb:13:in `block in singletonclass'
    /home/sunloverz/RubymineProjects/socialnews/app/assets/javascripts/letsrate.js.erb:65530:in `instance_eval'
    /home/sunloverz/RubymineProjects/socialnews/app/assets/javascripts/letsrate.js.erb:65530:in `singletonclass'
    /home/sunloverz/RubymineProjects/socialnews/app/assets/javascripts/letsrate.js.erb:65528:in `__tilt_74553360'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/tilt-1.3.7/lib/tilt/template.rb:144:in `call'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/tilt-1.3.7/lib/tilt/template.rb:144:in `evaluate'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/tilt-1.3.7/lib/tilt/template.rb:77:in `render'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/context.rb:193:in `block in evaluate'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `each'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `evaluate'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/processed_asset.rb:12:in `initialize'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:249:in `new'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:249:in `block in build_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:270:in `circular_call_protection'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:248:in `build_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/index.rb:60:in `find_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/processed_asset.rb:111:in `block in resolve_dependencies'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/processed_asset.rb:105:in `each'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/processed_asset.rb:105:in `resolve_dependencies'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/processed_asset.rb:97:in `build_required_assets'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/processed_asset.rb:16:in `initialize'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:249:in `new'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:249:in `block in build_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:270:in `circular_call_protection'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:248:in `build_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:169:in `find_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/index.rb:60:in `find_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/bundled_asset.rb:16:in `initialize'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:252:in `new'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:252:in `build_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/index.rb:93:in `block in build_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/caching.rb:19:in `cache_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/index.rb:92:in `build_asset'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.13/lib/sprockets/static_compiler.rb:19:in `block in compile'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:219:in `block in each_logical_path'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:206:in `block (2 levels) in each_file'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:196:in `each_entry'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:204:in `block in each_file'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:203:in `each_file'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/sprockets-2.2.2/lib/sprockets/base.rb:217:in `each_logical_path'
3.2.13/lib/sprockets/assets.rake:70:in `block (3 levels) in <top (required)>'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/actionpack-3.2.13/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
    Tasks: TOP => assets:precompile:primary
    (See full trace by running task with --trace)
    rake aborted!
    Command failed with status (1): [/home/sunloverz/.rvm/rubies/ruby-1.9.3-p38...]
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/file_utils.rb:45:in `call'
    Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

請檢查錯誤

“#的未定義方法`rate_path'”

嗨,好伙伴,請在部署到heroku之前先進行以下文件更改

------ enviorment.rb -----

::ActiveSupport::Deprecation.silenced = true

------ Production.rb -------

config.assets.compile = ['*.js', '*.css']
config.active_support.deprecation = :silence

------- application.rb -------

config.assets.enabled = true
config.assets.initialize_on_precompile = false

我在部署heroku時使用了此步驟,請確保您使用“ postgres”數據庫和“ thin”服務器,希望您能解決此問題。

我遇到了同樣的問題,我通過在routes.rb中添加此代碼來解決了這個問題

post '/rate', to: 'rater#create', as: 'rate'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM