Rails:模型实例方法还是辅助方法? [英] Rails: Model instance method or helper method?
本文介绍了Rails:模型实例方法还是辅助方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按照惯例,以下应定义为我的模型的实例方法还是辅助方法?
By convention, should the following be defined as an instance method of my model or a helper method?
# app/models/user.rb
class User < ActiveRecord::Base
def full_name
"#{first_name} #{last_name}"
end
end
或
# app/helpers/users_helper.rb
module UsersHelper
def full_name
"#{@user.first_name} #{@user.last_name}"
end
end
非常感谢.
推荐答案
使用第一个(保持模型),也是因为您可能想做其他事情,例如组合索引 :)
Go with the first (keep in model), also because you might want to do other stuff, like combined indexes :)
这篇关于Rails:模型实例方法还是辅助方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文