[英]Convert search feature from searchlogic to ransack rails 3
I'm trying to convert syntax from searchlogic and use ransack after an upgrade from rails 2.3.5 to 3.2.17 从Rails 2.3.5升级到3.2.17后,我正在尝试从searchlogic转换语法并使用ransack
My search_users method in my controller: 我在控制器中的search_users方法:
def search_users
term = params[:search]
show = Show.find(params[:show_id]) if params[:show_id]
# Get users in show audiences
show_user_ids = show.audiences.map(&:user_ids).flatten
# Remove the users that have full access
show_user_ids -= show.show_permissions.full.map(&:user_id)
@users = User.first_name_or_last_name_or_company_like(term).id_is(show_user_ids)
render 'shared/search_users'
end
The outdated code is: 过时的代码是:
@users = User.first_name_or_last_name_or_company_like(term).id_is(show_user_ids)
first_name_or_last_name_or_company_like
is syntax from searchlogic and since I don't have it on my app anymore, its undefined. first_name_or_last_name_or_company_like
是searchlogic的语法,由于我的应用程序中不再有该语法,因此未定义。
I can use @users = User.where(...)
and pass in term = params[:search]
? 我可以使用
@users = User.where(...)
并传递term = params[:search]
吗?
How would I pass in User.where first_name or last_name or company like term ? 我该如何传递User.where first_name或last_name或诸如term之类的公司?
Tried: @users = User.where(["first_name = :first_name or email = :email", { first_name: term, email: term }])
and its returning users with the search using first name only. 尝试过:
@users = User.where(["first_name = :first_name or email = :email", { first_name: term, email: term }])
及其返回用户仅使用名字进行搜索。
any help would be greatly appreciated! 任何帮助将不胜感激!
我使用以下代码使其正常工作:
@users = User.where(["first_name = :first_name or last_name = :last_name or company = :company", { first_name: term, last_name: term, company: term }])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.