views:

61

answers:

2

Hi...In Rails, is it ok to define logic in a controller with a model. For example, take there is an User Model, which is good design.

1)Leaving the UserModel with the CRUD models and moving all the other User Specific actions to a separate controller or
2)Add the user specific actions to the same UserModels

Thanks :)

+2  A: 

Fat models, thin controllers. If it's something that is done based fully on model attributes, or model attributes plus a few arguments, it goes in the Model. If it's something more complex, it probably still goes into a Model, just not one that is ActiveRecord::Base derived.

Terry Lorber
+1  A: 

hi Steve

I would prefer following approach

creating a separate User model in a different name space like business (to represent business login) and It will have all the business logic and there will be a separate user model which derives from ActiveRecord

example would be

class Business::User

#inside this all the user business logic goes

#you might need User (ORM) model when required like find action

end

and my controller will communicate with Business::User and this class will communicate with User (ORM) class for database actions

class User < ActiveRecord::Base

end

By this way you can separate your business login and ORM. either way you should keep your controllers thin while giving more processing to your models

cheers, sameera

sameera207