【问题标题】:Rails 3 Coffee Handler MissingRails 3 咖啡处理程序丢失
【发布时间】:2012-02-05 14:55:50
【问题描述】:

我在生产中使用 Ruby 1.9.3p0、Rails 3.1.2 和 Apache 和 Passenger。当我尝试创建一个远程函数时,它会抛出这个错误:

ActionView::MissingTemplate (Missing template video/loadVideo, application/loadVideo with
{:handlers=>[:erb, :builder], :formats=>[:js, "application/ecmascript", "application/x-
ecmascript", :html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, 
:multipart_form, :url_encoded_form, :json], :locale=>[:en, :en]}. Searched in

如您所见,:coffee 没有处理程序,这就是不处理文件 video/loadVideo.js.coffee 的原因;我运行命令 rake assets:precompile 但没有任何变化。

宝石文件 来源“http://rubygems.org”

gem 'rails', '3.1.2'

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'

gem 'will_paginate', '~> 3.0'
gem "bcrypt-ruby", :require => "bcrypt"
gem 'mysql'

#Problems in Debian, the error was:
#Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs #for a list of available runtimes. (ExecJS::RuntimeUnavailable)
#Solution: http://stackoverflow.com/questions/6282307/rails-3-1-execjs-and-could-not-find-a-javascript-runtime
gem 'execjs'
gem 'therubyracer'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.1.5.rc.2'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

group :test do
  # Pretty printed test output
  gem 'turn', '0.8.2', :require => false
end

【问题讨论】:

  • 里面有 coffee-rails gem 并不意味着它提供了一个咖啡处理器。
  • 请不要对模板使用驼峰式大小写。 Rails 的约定是使用下划线。 loadVideo 模板应该是 load_video

标签: ruby-on-rails-3 coffeescript passenger


【解决方案1】:

更改您的 Gemfile(将 coffee-rails gem 移到资产组之外)或更改您的 application.rb 设置 - 例如

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  # Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  Bundler.require(:default, :assets, Rails.env)
end

在开发环境应用程序默认加载来自:default, :development, :test, :assets 组的所有gem。咖啡处理程序来自coffee-rails gem,所以你必须加载它。

【讨论】:

  • 我遇到了同样的事情,一旦我将咖啡宝石移出资产命名空间,它就起作用了。我猜大多数人只在资产中使用咖啡脚本,而不是在视图中......奇怪的是,当 Gem 只在资产块中指定时,它在开发模式下工作。
猜你喜欢
  • 2013-01-09
  • 1970-01-01
  • 2011-11-08
  • 2012-08-24
  • 1970-01-01
  • 2012-08-09
  • 2013-06-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多