3

In my controller's create action, I have the following:

def create
  @article = Article.find(params[:id])

  respond_to do |format|
    if @comment.save
      format.js { render 'success.js' }
    else
      format.js { render 'failed.js' }
    end
  end
end

In my app/views/comments/failed.js.coffee, I have:

alert 'Write smth!' if $("#comments_error").length == 0

I receive the following error:

ActionView::MissingTemplate (Missing template comments/failed,
  inherited_resources/base/failed, application/failed with
  {:locale=>[:en, :en],
   :formats=>[:js, :html],
   :handlers=>[:haml, :builder, :erb]})

What am I doing wrong?

Joel Mueller
  • 28,324
  • 9
  • 63
  • 88
zolter
  • 7,070
  • 3
  • 37
  • 51

1 Answers1

7

At the time of this writing Rails does not support responding with a coffee-script file. This however is going to change.

Meanwhile in your Gemfile add:

gem 'coffeebeans'

then name your views action.js.coffee

As added bonus the file will pass through erb first, even if it's not declared in the file name.

kain
  • 5,510
  • 3
  • 27
  • 36
  • I have one more question, if I have some ruby code in my action.js.coffee file, what I should do? I tried rename action.js.coffee to action.js.coffee.erb, but I received error: ActionView::MissingTemplate – zolter Aug 02 '11 at 05:08