有没有办法让外国模型的某些领域是这样的:Rails的:获取与方法子模型的某些属性的“属性”
@user = User.find(:first, :select => ['`users`.`id`, `users`.`nickname`, `users`.`birthdate`, `users`.`sex`'], :conditions => ['`users`.`id` = ?', id])
city = @user.profile.city.attributes
随着attributes
我找回我的城市模型的所有属性。我只想得到一些。例如:
city = @user.profile.city.attributes[:name, :postcode]
是否可以通过保持语法如上所述简单?我想用attributes
来接收哈希。
非常感谢。
好:(谢谢! – Gozup 2013-03-11 11:12:50