I am new to the list and Rails (and Ruby, for that matter) and whilst I was a bit skeptical due to the hype it's causing, I am starting to really like it and there seems to be a really active and friendly community behind it which is an added bonus.
I have been writing web applications for a while now using different languages and frameworks (including hand-written ones just following best practices). I like it how Rails combines a lot of best practices and how its conventions guide the user to writing good applications (which I am convinced is possible on any kind of platform, but you need to know what you're doing, whilst Rails often takes you by the hand and stops you from getting off track).
There is two things I would like to comment on:
1. How Rails creates a mess on the client-side violating the MVC
2. Why I don't see the use of RJS
1. How Rails creates a mess on the client-side violating MVC
Whilst this has often been obscured by messy coding practices, you can easily think of the client side of a web application as implementing the MVC-paradigm.
M: HTML is the model. Good HTML does not include any presentational information. (e.g. that is why nowadays there is a wide consensus that HTML-tables are not meant to be used for layout)
V: CSS is the view. It defines how HTML data is presented on the screen. I admit that a certain part of the presentation is pre-defined by the ordering within the HTML, but stylesheets still allow you to fundamentally shape a page
C: JS is the controller. It defines the beaviour of elements on the page and in more advanced applications (especially AJAX) it manipulates the HTML data.
However, HTML allows you to break the paradigm. You can include CSS in your HTML (using style-tags) and you can include JS in your HTML (using onclick, onmouseover etc. event-handler-tags). The fact that MVC is so pervasive on the server side these days seems to indicate that it has some value, though. So you can mess it up on the client side but, as with any best practice, you usually realise after a while that you're better off when you don't.
An attempt has been made by Luke Redpath and Dan Webb by providing the UJS plugin (http://www.ujs4rails.com/). However, Dan lines out himself that it is a somewhat half-hearted attempt (http://www.danwebb.net/2007/6/16/the-state-and-future-of-the-ujs-plugin) The plugin may create cleaner code in the end and may save you band-width by keeping your JS out of your HTML (thus having to download it once only). But to my mind, UJS is above all about programming practice, about clean and maintainable code and the plugin doesn't help that.
2. Why I don't see the use of RJS
I have spent a fair amount of time pondering about it, I have read a lot of enthusiastic tutorial, but still I fail to see the use of RJS. Essentially, RJS provides Ruby functions that output some bits of JS code. Such as other functions (for example the form helpers, I hope I am using the right terminology here) output HTML.
In terms of HTML that makes sense. HTML is a markup language, not a programming language. There is no way to write functions, makros or whatever in HTML. So if you have a certain complex HTML-construct (e.g. a complex table or a custom control made up of various tags), you would have to write it by hand again and again. So it's useful to have a Ruby function that does the job and reduces the work to a single line of Ruby instead of say 20 lines of HTML.
That doesn't make your code DRYer, it doesn't make life easier. Yes, I know, it saves you from writing JS. But JS is not difficult and there are brilliant libraries and it's well worth the effort of learning. Because what price do you pay using RJS the way I see it used most of the time?
- it seems to me that with any serious JS-based application you will quickly run into the limitations of RJS and you will need real JS, anyway (Dan Webb seems to think along similar lines: http://www.danwebb.net/2006/11/17/rjs-minus-r)
So for the moment, for my first Rails project, my approach will be:
I will use Rails for the server side and I won't let it mess with the client-side. Rails belongs to the server and that's where it's brilliant. For the client, there is HTML, JS and CSS already and used properly they can be brilliant in their own way. I will treat JS just as CSS: I will put it in the public folder and write only clean UJS using prototype and lowpro which make it dead easy. I will debug using Firebug on the client side.
I am very keen on hearing your comments! Thanks