small medium large xlarge

Generic-user-small
16 Jun 2008, 20:19
Wayde Gilliam (18 posts)

Just curious.

Thanks - wg

Samr_small_pragsmall
16 Jun 2008, 21:16
Sam Ruby (634 posts)

Thursday, June 05, 2008

Generic-user-small
17 Jun 2008, 02:03
Wayde Gilliam (18 posts)

I see its been updated to work with 2.1 … but the code doesn’t seem so.

For example on p.131 you have “respond_to { format format.js }” whereas in 2.1, I’d expect something more like this …

respond_to do |format| format.html { … } format.xml { …} format.js … end

Samr_small_pragsmall
17 Jun 2008, 02:37
Sam Ruby (634 posts)

do…end and {…} accomplish the same thing (there is a minor difference as to precedence order, but that doesn’t apply here).

The nested {…} blocks are optional, and aren’t needed in this case.

The net is that the following are essentially identical:

respond_to { |format| format.js }
respond_to do |format|
  format.js {}
end

Let me think about this a bit more.

Generic-user-small
17 Jun 2008, 04:32
Wayde Gilliam (18 posts)

You’re right. I still think it might be better to re-write the code for the Depot app using “do” statements for a number of reasons. First, 2.1 generated code uses this. Second, I think it makes for the most straight-forward way of falling back to plain HTML in non-AJAX-aware browsers and adding new formats.

Anyways, like you said … they both accomplish the same thing. It just seems the “do” is more 2.1 and makes for more easily understand code when it comes to the cases mentioned above.

Thanks

Samr_small_pragsmall
17 Jun 2008, 20:26
Sam Ruby (634 posts)

OK, I’m convinced. The next beta will use the following form:

respond_to do |format|
  format.js
end
Generic-user-small
17 Jun 2008, 22:48
James West (104 posts)

Hi I’m from a Delphi background and I must say that the second example feels much more natural and readable to me.

Whatever I feel about the code examples provided I have to say that if this is the way that Ruby is going then this is the way I would like to be shown how to do things by this book.

Just my tuppence worth.

Generic-user-small
20 Jun 2008, 03:30
Wayde Gilliam (18 posts)

Thanks Sam! Looking forward to the next drop.

You must be logged in to comment