Home How does ransack search works on an array list?
Reply: 0

How does ransack search works on an array list?

user886 Published in May 22, 2018, 4:36 am

I am using Rails 4.2.5, Ruby 2.2, ransack. I am trying to implement search functionality using Ransack. I have something like:

emails = ["abc@abc.com", "a@a.com", "b@b.com"]
users_list = emails.map{|a| User.where(email: a).first}
checked_in_users = Kaminari.paginate_array(users_list)

This gives me proper list of users in the page. But if I want to search by email, what should I do ?

@q = checked_in_users.ransack params[:q]

This gives me:

"NoMethodError (undefined method `ransack' for #<Array"

HAML code:

= search_form_for [@q], url: users_path(some_id: id) do |form|
  = form.text_field :user_name_or_user_email_cont, placeholder: 'Name or email', class: 'form-control'

What would be the correct way to do it with ransack ?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.33274 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO