Rails view decorator: Draper VS ActiveDecorator

rainchen · 2012年12月12日 · 2774 次阅读

前序: Draper (https://github.com/drapergem/draper) 和 ActiveDecorator (https://github.com/amatsuda/active_decoratorview) 一样都是用于偶合 helper 和 model 的工具。

铺垫: 一个比较常见的场景:显示用户头像并连接到用户主页,在普通的 view 代码中需要使用很长的一段: <%= link_to image_tag(user.avatar.url), user_profile_path(user) %>

... 通过使用 view decorator 简化为: <%= user.avatar_tag %> <%= user.name_with_gender %>

文长详见: http://hi.baidu.com/rainchen/item/7e63a5cfbfe02abb0c0a7be7

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号