Ok to instantiate an object in the View?

后端 未结 1 617
无人共我
无人共我 2021-01-26 00:57

Is it ok to instantiate an object in a View before passing it to a partial?

<%= render :partial => \"trade_new\", :locals => {:trade=>Trade.new(\"e\"         


        
相关标签:
1条回答
  • 2021-01-26 01:07

    Firstly, it is okay to instantiate an object in the view. Nothing will probably blow up in your face. However, then you miss the whole advantage of splitting your architecture into tiers.

    It is better to instantiate the object in the controller. Some of the reasons include - better reuse, much simpler testing, better design because of the decoupling.

    See the articles on presentation patterns here.

    0 讨论(0)
提交回复
热议问题