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

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
@markbates

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

@josevalim

This comment has been minimized.

Show comment Hide comment
@josevalim

josevalim May 18, 2011

Contributor

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.

Contributor

josevalim commented May 18, 2011

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

This comment has been minimized.

Show comment Hide comment
@markbates

markbates May 18, 2011

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

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

@markbates

This comment has been minimized.

Show comment Hide comment
@markbates

markbates May 18, 2011

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.

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

This comment has been minimized.

Show comment Hide comment
@josevalim

josevalim May 18, 2011

Contributor

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.

Contributor

josevalim commented May 18, 2011

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

This comment has been minimized.

Show comment Hide comment
@josevalim

josevalim May 18, 2011

Contributor

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

Contributor

josevalim commented May 18, 2011

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

This comment has been minimized.

Show comment Hide comment
@stuartmg

stuartmg May 18, 2011

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!

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

This comment has been minimized.

Show comment Hide comment
@josevalim

josevalim May 18, 2011

Contributor

That would easily work as a coffeescript-rails plugin.

Contributor

josevalim commented May 18, 2011

That would easily work as a coffeescript-rails plugin.

@fbjork

This comment has been minimized.

Show comment Hide comment
@fbjork

fbjork May 20, 2011

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

fbjork commented May 20, 2011

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

@russfrisch

This comment has been minimized.

Show comment Hide comment
@russfrisch

russfrisch May 20, 2011

+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.

+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

This comment has been minimized.

Show comment Hide comment
@guilleiguaran

guilleiguaran May 20, 2011

Owner
@DevL

This comment has been minimized.

Show comment Hide comment
@DevL

DevL May 21, 2011

Contributor

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.

Contributor

DevL commented May 21, 2011

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

This comment has been minimized.

Show comment Hide comment
@dhh

dhh May 22, 2011

Owner

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

Owner

dhh commented May 22, 2011

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

@JeanMertz

This comment has been minimized.

Show comment Hide comment
@JeanMertz

JeanMertz May 27, 2011

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!

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

This comment has been minimized.

Show comment Hide comment
@yury

yury Jul 9, 2011

Contributor

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

Contributor

yury commented Jul 9, 2011

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

@markbates

This comment has been minimized.

Show comment Hide comment
@markbates

markbates Jul 9, 2011

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.

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

This comment has been minimized.

Show comment Hide comment
@yury

yury Jul 9, 2011

Contributor

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

Contributor

yury commented Jul 9, 2011

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

@markbates

This comment has been minimized.

Show comment Hide comment
@markbates

markbates Jul 9, 2011

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

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

@Gregg

This comment has been minimized.

Show comment Hide comment
@Gregg

Gregg Aug 12, 2011

Contributor

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.

Contributor

Gregg commented Aug 12, 2011

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

This comment has been minimized.

Show comment Hide comment
@joefiorini

joefiorini Aug 12, 2011

Contributor

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

Contributor

joefiorini commented Aug 12, 2011

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

@russfrisch

This comment has been minimized.

Show comment Hide comment
@russfrisch

russfrisch Aug 12, 2011

The HTML5 Boilerplate based application template adds this mark's gem to
the GemFile (commented) when creating a new rails 3.1 app. [shameless plug
:)]

https://github.com/russfrisch/h5bp-rails/blob/master/h5bp.rb#L65

Hopefully this functionality makes it into rails core soon. Like Gregg, I
agree that if CoffeeScript is the default, it should be able to be used
everywhere in place of JavaScript.

On Fri, Aug 12, 2011 at 11:04 AM, joefiorini <
reply@reply.github.com>wrote:

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

Reply to this email directly or view it on GitHub:
#1130 (comment)

The HTML5 Boilerplate based application template adds this mark's gem to
the GemFile (commented) when creating a new rails 3.1 app. [shameless plug
:)]

https://github.com/russfrisch/h5bp-rails/blob/master/h5bp.rb#L65

Hopefully this functionality makes it into rails core soon. Like Gregg, I
agree that if CoffeeScript is the default, it should be able to be used
everywhere in place of JavaScript.

On Fri, Aug 12, 2011 at 11:04 AM, joefiorini <
reply@reply.github.com>wrote:

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

Reply to this email directly or view it on GitHub:
#1130 (comment)

@guilleiguaran

This comment has been minimized.

Show comment Hide comment
@guilleiguaran

guilleiguaran Aug 15, 2011

Owner

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

Owner

guilleiguaran commented Aug 15, 2011

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

@markbates

This comment has been minimized.

Show comment Hide comment
@markbates

markbates Aug 15, 2011

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.

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

This comment has been minimized.

Show comment Hide comment
@jlebrech

jlebrech Jan 12, 2012

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.

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

This comment has been minimized.

Show comment Hide comment
@davidmles

davidmles Nov 17, 2012

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.

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

This comment has been minimized.

Show comment Hide comment
@codyrobbins

codyrobbins Jul 11, 2013

Contributor

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.

Contributor

codyrobbins commented Jul 11, 2013

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