What needs to be configured for Heroku to handle templates based on CoffeeScript?

前端 未结 3 1507
青春惊慌失措
青春惊慌失措 2020-12-30 06:32

I have a create action that handles an AJAX request. On my development machine, a template named create.js.coffee is successfully processed to generate a javascript response

相关标签:
3条回答
  • 2020-12-30 06:57

    I'm even later to the party, but I just had the same problem and there's a simple explanation:

    The "assets" group of gems in the Gemfile are for development only. Heroku does not load these gems in production because it relies on its own stable versions for its Asset Pipeline.

    If you're using a special gem that sounds like it's related to the asset pipeline but doesn't actually belong to a standard pipeline (e.g. the "coffeebeans" gem) you should keep that gem outside the "Assets" group.

    I just tested this theory and it worked for me.

    0 讨论(0)
  • 2020-12-30 07:19

    I'm a bit late to the party, but here is my solution, as posted on Github.


    I just ran into a problem where my create.js.coffee file was working in development but stopped working in production (on Heroku). The logs show that Rails isn't even looking for a coffee handler:

    2011-10-14T08:26:29+00:00 app[web.1]: ActionView::MissingTemplate (Missing template page_blocks/create, application/create with {:handlers=>[:erb, :builder, :haml], :formats=>[:html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json], :locale=>[:nl, :nl]}. Searched in:
    2011-10-14T08:26:29+00:00 app[web.1]:   * "/app/app/views"
    2011-10-14T08:26:29+00:00 app[web.1]: ):
    

    This is the (important) part of my Gemfile:

    group :assets do
      gem "sass-rails", "~> 3.1.0"
      gem "coffee-rails", "~> 3.1.0"
      gem "uglifier"
      gem "compass", "~> 0.12.alpha"
    end
    
    # asset templates
    gem "jquery-rails"
    gem "haml"
    

    Only after I moved coffee-rails outside of the :assets group, things started working. Perhaps it would be a good idea to somehow make this clear in the readme, and perhaps even ship Rails with the coffee-rails plugin being placed outside the assets group.

    0 讨论(0)
  • 2020-12-30 07:19

    On heroku cedar you need to add bin to your path as per the very last section of this page Rails 3.1+ Asset Pipeline on Heroku Cedar. "If you need to compile assets at runtime, you must add bin to your PATH to access the JavaScript runtime."

    0 讨论(0)
提交回复
热议问题