nice and neat!~
Couldn't download file :(
Actually I can't download any episode, strange.
Hoping for a quick fix :)
Congratulations on the popularity of these. I really like them. I couldn't download them either, until just now :) Had to wait for a break in the queue I guess.
Download is working again!
Really nice this post, but could you create a screencast about test unites in views? Thanks!
Sorry about the downtime guys. I guess that's the price to pay for the cheap Dreamhost bandwidth. :/
Ryan,
These are really great!
One suggestion: Many people primarily consume your videocasts via iTunes and may only visit the home page.
It took me many weeks before I found out you had code examples in the permalinks. I'd encourage you to have a "Read more..." or "Read Show Notes/Code..." link from each post in the main index.
Just a thought, keep it up!
I would disagree with the final refactoring of the loop into a partial/collection. It doesn't really slim your code at all, and will make future alterations more of a hassle as you switch between the two files. Good stuff though
I'd be interested in a review of more advanced concepts like using concat, capture, content_for - and when you might use those in conjunction with or instead of helper methods - e.g. the <% title "blog" %> at the top, how was that implemented?
@crayz, yeah, the partial refactoring is questionable. I showed it mainly for variety to cover the different refactoring techniques.
The "title" method was covered in a previous episode: http://railscasts.com/episodes/30.
I have covered concat and capture in a previous episode as well: http://railscasts.com/episodes/40
Cool, I'll check them both out - thanks Ryan
These continue to be a great help! This is one of the best ones yet, thanks Ryan!
Continually impressed by the quality of your screencasts - thank you.
Minor niggle: I believe #to_a – you use "line_items.to_a" – is deprecated; you can do "Array(line_items)" instead.
@Henrik, thanks. Out of curiosity, where did you hear that to_a was deprecated?
Being unaware of the ability to sum FixNum/Float arrays I've found inject to be a great tool for that particular job.
You mentioned that you would be interested in what others are doing and most of my sums look like:
@cart.items.inject(0.0){|total,item|total+(item.price*item.quantity)}
This is also a hack, but inject is very powerful and using it in simple cases like this has helped me wrap my head around much more complicated data transitions using relatively simple injects.
Ryan: Just from deprecation messages in the console: "warning: default `to_a' will be obsolete".
Googling it a bit, it seems that it's specifically Object#to_a that is/will be deprecated. Various other objects have their own #to_a (see "ri to_a") which are not deprecated.
I found this screencast extremely useful, thanks!
I liked too much the _with_index, but when I tried to use it with a grouped instance variable: @items.each_with_index do |category, tasks, i| but it's not working :( any idea?
@Mahmoud, each_with_index only passes two arguments into the block (the item and the index). Here you're trying to pass 3 arguments which it can't do.
I don't matter, you should found me how to get rid of the <%i=0%> and the <%i+=1%> I'm having in my code! otherwise the scrrencast is useless!
No I'm joking! , your screencasts are just making of us very tough people and high class coders, You have to assume!
Good luck!
@Mahmoud, I recommend asking the question on railsforum.com where you can post the full code. I'll try to reply there if I know the answer.
Ryan, nice example!
I'm wondering about the total_price method on cart.rb. As I don't have a similar code here (hey, it's already late now), I'm wondering if we write the method this way
def total_price
line_items.inject(0) {|memo,item| memo += item.full_price}
end
can speed up things a little, avoiding the to_a and sum methods. What you think?
Best regards.
@TaQ, I believe the "sum" method uses inject under the hood, so I doubt it would give you a speed boost.
If I use a collection. How do I know if the counter is at the last position?
@Umang, you can see if the current item matches "items.last":
if item == items.last
Thanks Ryan! So, the partial counter is just an integer. Got it!
Amazing Screencasts Ryan! Thanks for all the hard work!
We see in advance that, by virtue of a synthesis in which what is meant coincides and agrees with what is itself given, we have not simply lost scientific evidence for phenomenology; we retain it by virtue of a synthesis in which what is meant coincides and agrees with an object.



