Slides from RailsConf

Posted by Chad Pytel

Jun 02

slides

On Sunday at 1:50 I had the pleasure of giving my talk Advanced Active Record Techniques: Best Practice Refactoring. Thank you to all who gave me the positive feedback afterward, I really appreciate it.

Here are the slides for the presentation.

If you enjoyed this presentation, please recommend me on Working With Rails.


Comments on this post

Trevor Turk

Jun 03

Trevor Turk said,

Great slides – I wish I could have made it to the presentation (and RailsConf in general, really).

Just a small note – I think you could clean up your final controller action on page 69 a tiny bit more using some new Rails 2.1 goodies – namely, the ability to use blocks with new and create:

http://github.com/rails/rails/commit/dd120ede53eaf71dee76894998a81626b7a689fc#L1R610

You might even be able to squeeze the first 5 lines into 2, if you wanted to go nuts.

Chad Pytel

Jun 03

Chad Pytel said,

Thanks, Trevor. You’re right, the new block syntax for new and create would have been great to include here.

On a related note, to all who grab the slides and didn’t see the talk – One thing that doesn’t come through in the slides was what I was actually saying while they were up on the screen – and that was that if it were a talk on controllers, I’d refactor everything further.

Perhaps I’ll clean up my slide notes and post a copy of the slides with the notes attached.

Adam Grant

Jun 05

Adam Grant said,

Hey Chad,

Great slides! I especially agree with the callback refactoring. It makes things alot easier to read.

I was curious about slide 91, specifically:
1
2
3
4
5
6
7
8

class << self
   TYPES.each do |role_type|
    define_method "#{role_type}?" do
      roles.exists?(:name => role_type)
    end
  end
end

Shouldn’t that be in the User model, and not the Role model?

If that’s the case, then in terms of it’s use, is the correct call:

@user.roles.admin?

Chad Pytel

Jun 05

Chad Pytel said,

Yes, that’s correct – the call will be @user.roles.admin?

That was one of the things that I said during the presentation, but that wasn’t included on the slides (it probably should be). I also noted that if you really wanted to have an has_role? method on user, I’d be ok with that as well, but that this is the way I’d do it.

I’m glad you enjoyed the slides.


Sorry, comments are closed for this article.

© 2000 - 2009 by thoughtbot, inc.
written by a bushel of tiny robots