Are view models used in rails?

后端 未结 1 839
情书的邮戳
情书的邮戳 2021-02-05 05:08

I\'m starting to develop a small application in ruby on rails and many questions arise. I should say that I have about 1 year of experience with ASP.NET MVC and feel at home wit

相关标签:
1条回答
  • 2021-02-05 05:48

    If I understand the notion of View Model correctly, it's a concept that's not immediately obvious in Rails, but neither is it forbidden/frowned-on or otherwise not allowed. There's no specific requirement for a perfect one-to-one mapping of models to tables so you're free to work at the level of abstraction that's appropriate.

    I don't think referencing multiple models in a view is considered particularly bad (if it is, then I have some areas that need a little rework) although updating multiple models from a single view can get a bit tricky.

    Anyway, in Rails I think we're talking about what seems to be mostly referred to as the "Presenter" pattern. Some references (Google "Rails Presenter Pattern" for more than you probably want or need):

    • http://blog.jayfields.com/2007/03/rails-presenter-pattern.html
    • http://gilesbowkett.blogspot.com/2007/10/my-version-of-rails-presenters.html
    • http://blog.jayfields.com/2007/10/extending-rails.html (mentions that DHH used presenters in Highrise)
    0 讨论(0)
提交回复
热议问题