Rails MVC: How to write models

thin views, thin controllers, fat models How to deal with fat models? »
Andrzej Krzywda

Andrzej Krzywda

Rails since 2004
Arkency, CEO


Logic in views is bad

LOGIC in CONTROLLERS IS BAD

FAT MODELS
USER objects

Guest
User
Admin
SuperAdmin
Partner
default_scope

no nice way to disable it.
it's better to use
user.products
admin.products
avoid static methods

easy permissions mistakes
not good OOP
user.items.find(id) vs 
Item.find(id, :conditions => {:user => self})
IF statements

to me it's always a possible smell

instance_of?

polymorphism smell
CODE SMELLS
if current_user == nil

else

end

bad code
DON'T ASK, TELL
Custom exceptions
controller calls only one model
 method in one action
modules
concerned_with
AOP - aquarium

Loading comments...

Please log in to add your comment.

Report abuse

More presentations by Andrzej Krzywda

  • Using Exceptions

    Andrzej Krzywda on

    In a typical MVC application, there is a problem how the communication between the Controller and the Model should look like. This presentation shows how ...

  • test 2

    Andrzej Krzywda on

    test 2 description

  • Kurs Rails 3

    Andrzej Krzywda on

    Przykładowe problemy