开发者

Rails Controller [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answe开发者_StackOverflow社区rs to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

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 :)


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜