开发者

Rails - How to avoid messy conditions in my views

开发者 https://www.devze.com 2023-03-10 05:12 出处:网络
I\'m still fairly new to rails and trying to learn its \'best practices\'. I\'ve noticed when I\'m drawing up my views to display a report, my views are starting to look cluttered with if-else-then co

I'm still fairly new to rails and trying to learn its 'best practices'. I've noticed when I'm drawing up my views to display a report, my views are starting to look cluttered with if-else-then conditions. If there are some good way开发者_Go百科s to avoid such mess, please advise.


General advice would be to make sure that any domain logic exists in your models, rather than the view.

Also, extract mark-up into partials if your views are getting too long.

You might also want to look at the MVVM pattern: http://en.wikipedia.org/wiki/Model_View_ViewModel

0

精彩评论

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