Forum Series Part 6: Search with Ransack Discussion
Thanks for the great video Chris!
Does ransack support autocomplete while typing in a search query? I checked out the documentation on github, but it doesn't mention anything about it.
Also, what do you think about Searchkick (https://github.com/ankane/s... Would love to see a video on this too!
Thanks again!
You can do autocomplete by having it query the URL for JSON response each time someone types a character. My suggestion is to try hooking it up with jQuery UI's autocomplete. http://jqueryui.com/autocom...
Just implemented this in conjunction with Ryan's episode 370 http://railscasts.com/episo.... Have some really cool advanced search features now working on my customer index page.
Now just need to figure out how to rspec this stuff (I find BDD doesn't work in the learning phase).
@excid3:disqus in the controller why isn't it ForumThread.search(params[:subject_cont]) ?
You need to pass in params[:q] so it passes in both the name of the field and the search you want to do on it. Since it supports multiple fields in search, you pass them all in instead of just one.
@excid3:disqus Do you know how to include a has_many through relationship in the search? Specifically, I'd like to search for tags associated with a recipe. The setup is similar to acts_as_taggable but I rolled my own so to speak. I tried :name_or_category_or_tags_cont but got an error.
It looks like on the Ransack docs, they do this:
class Artist
has_many :memberships
has_many :musicians, through: :memberships
end
artists = Artist.ransack(musicians_email_cont: 'bar')
Hey Chris! Nice one! I'm already using ransack gem based on this tutorial. On the top of this for some models in my app I would like to take this one step further by using some AJAX/jQuery autocomplete search/sorting for my table. I found a bunch of things, but every given solution I found seemed to be outdated. As of Nov 2015, could you tell me what gems/jQuery plug-ins/etc I should use to implement both the ajaxified searching and sorting feature that will be good enough in production? Thanks!
Great video! I want to download the search results into an Excel file and am able to kind of do this. I'm having 2 problems.
First, when I use the @projects variable below, it works but only allows me to download 40 results as per the will_paginate gem.
@projects = @q.result.includes(:vendor, :service_category).paginate(:page => params[:page], :per_page => 40)
Second, I have a standard download (with many tabs) that is not dependent on the search results. I want there to be two exports on the projects index page- one which is the standard spreadsheet and the other that only includes the search results. Can I do this in the index action?
This is what I have in my respond_to block
format.xls { response.headers['Content-Disposition'] = "attachment; filename=\"projects_list_created_on_#{formatted_date_today}.xls\""
and there is a corresponding index.xls.erb file in the views.
Thank you in advance for any advice!
How would you add ransack if your post controller looks like this?
def index
if params[:category].blank?
@posts=Post.all.order("created_at desc").paginate(:page => params[:page], per_page: 15)
else
@category_id = Category.find_by(name: params[:category]).id
@posts = Post.where(category_id: @category_id).order("created_at DESC").paginate(:page => params[:page], per_page: 2)
end
Hi Chris, I added Ransack to search for users and the search field always is pre-filled with the logged-in user's email and has to be deleted manually. Before a search the field is pre-filled again. Any hint on what's going on?
Do I need to have eelastic search installed for this setup or searchkick?
I basically want to get this to work : https://gorails.com/episodes/global-autocomplete-search?autoplay=1
By following this tutorial will I have the setup needed to do the above link as well?