Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed

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

wants to merge 1 commit into from

Conversation

markbates
Copy link

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

@josevalim
Copy link
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.

@josevalim josevalim closed this May 18, 2011
@markbates
Copy link
Author

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

@markbates
Copy link
Author

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
Copy link
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.

@josevalim
Copy link
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.

@stuartmg
Copy link

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
Copy link
Contributor

That would easily work as a coffeescript-rails plugin.

@fbjork
Copy link

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
Copy link

+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
Copy link
Member

It's available as gem: https://github.com/markbates/coffeebeans

@DevL
Copy link
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
Copy link
Member

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
Copy link

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
Copy link
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
Copy link
Author

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
Copy link
Contributor

yury commented Jul 9, 2011

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

@markbates
Copy link
Author

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

@Gregg
Copy link
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
Copy link
Contributor

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

@russfrisch
Copy link

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
Copy link
Member

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

@markbates
Copy link
Author

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
Copy link

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
Copy link

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
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet