开发者

Rails future & Javascript

开发者 https://www.devze.com 2023-02-16 12:49 出处:网络
David H.H. announced recently that jquery is going to be the default in Rails 3.1, and that Prototype helpers / RJS are going into a gem.

David H.H. announced recently that jquery is going to be the default in Rails 3.1, and that Prototype helpers / RJS are going into a gem.

What does that mean for the future? Should we pr开发者_如何转开发ogressively forget about things like javascript helpers, RJS, and all these fun parts of rails? And start coding with jquery/json in mind?

I'm not against that at all, but I have to admit I find RJS really fun to use...


Yes, unobtrusive JavaScript has won. Many people write now directly JS / jQuery code in ERB templates. jQuery code to replace some DOM node with a partial is only slightly longer than equivalent RJS code. Regarding JS helpers, it should be quite easy to replace all of them with unobtrusive JS code. Check how data-remote is handled in jQuery Rails driver.

This trend makes sense because web apps have more and more JS code which cannot be written in RJS. It is better to use two languages than three.

If you don't like JavaScript syntax then check out CoffeeScript. Which will be definitely more popular than RJS.

Long term future probably belongs to pure JS frameworks like SproutCore. Server side will process only JSON data. However these new techniques will be used only in new apps. Generally it doesn't make sense to upgrade existing apps to the new model.

0

精彩评论

暂无评论...
验证码 换一张
取 消