Added ability to use foo.js.coffee files in views. #1130

Closed
wants to merge 1 commit into from
@markbates

With this patch it is now possible to use CoffeeScript to respond to JS requests.

@josevalim
Ruby on Rails member

That's a very well done pull request, thanks! But we need to handle this pull request in another way and probably for Rails 3.2. Maybe by partially supporting tilt, although they lack proper encoding support and other Rails features.

@josevalim josevalim closed this May 18, 2011
@markbates

Mind if I ask why another way? Not sure I understand why we this isn't the correct way to implement this.

@markbates

I can understand why refactoring the rendering engine to use Tilt would be a good idea. I just think this is a missing piece of functionality in 3.1 that people will be complaining about when it's released. I know this was one of the first things I tried to do in the beta and was disappointed to learn I couldn't use CoffeeScript instead of vanilla JS for my Ajax requests.

@josevalim
Ruby on Rails member

Sure. If we add this as it is, we would be just duplicating code. And code duplication would easily lead for difference of behaviors from coffee being served from sprockets than rails. We should not have two code paths for this, but only one.

@josevalim
Ruby on Rails member

I totally agree with your disappointment but it should be solved without duplicating the same JS preprocessor code that is already inside sprockets/tilt.

@stuartmg

Pretty disappointed with this one getting closed - the majority of the javascript in my app related to responding to ajax requests and this prevents me from using coffeescript for that. Please reconsider!

@josevalim
Ruby on Rails member

That would easily work as a coffeescript-rails plugin.

@fbjork

Would love to see this behavior in Rails 3.1, can't this be solved using just one code path then?

@russfrisch

+1 For this becoming part of Rails 3.1. Having CoffeeScript as the default and yet having to respond to ajax using vanilla JavaScript feels broken to me.

@guilleiguaran
Ruby on Rails member
@DevL

Regardless when and how this missing piece of functionality gets implemented in Rails itself, I think that we all can be in agreement that it should. While we wait for the final implementation we can use the available gem and then, hopefully easily, refactor whatever code we write now to use whatever solution the Rails team finally put in place.

@dhh
Ruby on Rails member

Once we have a fast, clean implementation, it's welcome in core. 3.2 is a more likely target, though.

@JeanMertz

Just wanted to put my vote here for this functionality. I tried to use coffeescript in an xhr request but it didn't work. Great that it'll probably be in 3.2 so for now I'll go grab the gem by markbates. Thanks!

@yury

As I understand, this approach compiles CoffeeScript every time even in production. So here is alternative as a gem coffee-views.

@markbates

This is almost the same as coffee beans. Why not merge these fixes into that gem so there's only one? I'll gladly pull the changes in. There are a lot of people using coffee beans already and they'd probably really like the changes.

@yury

@markbates I can prepare pull request, if you ok with <%=%> changes.

@markbates

Can you explain them a bit more? Not sure I really understand what they do? Do they wrap everything in the j method?

@Gregg

Just ran into this myself, putting together the next version of Rails for Zombies.

If you're going to recommend people use CoffeeScript in their new Rails applications, then you should allow them to use JUST CoffeeScript in their Rails applications.

I understand there may be architectural issues, I'm just going to have to teach all new Rails developers to use Mark Bates's Gem.

@joefiorini

Can you include the coffeebeans gem in the Gemfile by default?

@russfrisch
@guilleiguaran
Ruby on Rails member

Now this supported in Rails 3.1 through the coffee-rails plugin (included by default in Gemfle)

@markbates

Glad this is somewhat included in rails 3.1. I would love to have seen this touted as part ofbthe last RC. I don't recall seeing that change in the list.

@jlebrech

rather than allow a coffescript_for tag by default, why not have a /assets/javascripts/model/action.coffee.erb so that it can be precompiled into a .js.erb file. if it's in assets then it can be added to the head of the view automatically.

@davidmles

I just faced this problem today. I have also the opinion of including coffeebeans in Gemfile by default, or telling about this problem in the docs instead.

@codyrobbins

Despite support for Coffeescript view templates we still have a problem whereby .js.coffee templates are preprocessed with ERB when intuition says they shouldn’t be; and an error is thrown for .js.coffee.erb templates. This is being discussed on rails/coffee-rails#13.

@codyrobbins codyrobbins referenced this pull request in rails/coffee-rails Aug 7, 2013
Closed

.js.coffee.erb doesn't work in app/views #36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment