0
votes

I'm trying to convert syntax from searchlogic and use ransack after an upgrade from rails 2.3.5 to 3.2.17

My search_users method in my controller:

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.

I can use @users = User.where(...) and pass in term = params[:search]?

How would I pass in User.where first_name or last_name or company like 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.

any help would be greatly appreciated!

1

1 Answers

0
votes

I got it working, used following code:

@users = User.where(["first_name = :first_name or last_name = :last_name or company = :company", { first_name: term, last_name: term, company: term }])