Shamoon
Shamoon

Reputation: 43531

Loading .coffee files via a view in Rails

My controller is as follows:

  class CommentLoaderController < ApplicationController
    respond_to :js
    def show
      puts 'here'
      @client_id = params[:id]
      respond_with @client_id
    end
  end

It loads a .js file which has some .erb markup in it. I'd like to load a CoffeeScript file, compiled to JS on the fly. Is this possible with Rails 3?

Upvotes: 2

Views: 373

Answers (1)

Adam Pope
Adam Pope

Reputation: 3274

I think this blog post that one of my colleagues wrote today might help

http://www.storm-consultancy.com/blog/development/random-bits/todays-gotcha-when-coffeescript-templates-in-rails-work-in-development-but-not-production/

It turns out that Rails won’t compile CoffeeScript templates by default, but you can install the Coffeebean gem and it magically works.

Upvotes: 1

Related Questions