我在ActiveScaffold working中有一般的字段搜索。我不确定如何做这个更复杂的搜索。
我有两个表,Account和User,我想搜索电子邮件并返回匹配帐户的列表。email字段位于User和Account has_many :users中。
我在思考查询应该如何发生时遇到了麻烦。理想情况下,我想做这样的事情:
Account.where(email: 'search_term').all
或
User.where(email: 'search_term').includes(:account).all
发布于 2013-04-24 04:09:46
如果您想从一个表中搜索数据并从(包括)另一个表中返回结果,只需将这些外列添加为虚拟列:
在用户控制器中:
active_scaffold :user do |conf|
conf.search.columns << :email
conf.list.columns << :account
#...
end就是这样,没有问题:)
如果account列结果显示代码为<#23423..这是因为Active Scaffold不知道如何描述类记录,所以您可以告诉它如何在模型中使用:
class Account << ActiveRecord::Base
....
def to_label
"cod: #{account_number}"
end https://stackoverflow.com/questions/15749946
复制相似问题