in Education by
Having a nightmare with this one and think i'm going to go crazy. It must be something simple. I have ransack working on my listings#index. It renders the results in a JS partial no problem using remote: true in the search form. All good. however.... I want this same functionality to work on the root_page of the app. So essentially a search bar that will show the search results in a partial just under the bar when a user searches. I can get this to work normally with ransack whereby the page refreshes and the results show from the partial. It will not for the life of me render the partial as JS just like how the listing controller does it. The code bits are pretty much similar. I'll add them both below. Ransack works, just doesn't recognise the remote: true bit. I've looked into inspect on chrome and can actually see that for some reason the form class doesn't register correctly. I'll screenshot both working and non working bits. So it's just a matter of the Ransack search query not recognising the remote: true by the looks of it. Any guesses? Does Ransack require something special to be added to the form to enable it to work from a page named home.html.erb? instead of index.html.erb? Would love a set of eyes to literally tell me i'm doing something stupid here. Thanks. Working code snippets for searching in the listing_controller listing#index def index @search = Listing.ransack(params[:q]) @data = @search.result(:distinct => true) @listings = @data.to_a end listing index.html.erb <%= search_form_for @search, remote: true do |f| %> <%= f.search_field :title_or_content_or_aircraft_highlights_or_airframe_engine_apu_weight_or_avionics_connectivity_or_interior_or_exterior_or_additional_info_cont, placeholder: "Search by keyword..", class: "form-control" %> <%= f.submit "Show results", class: "btn btn-secondary btn-lg btn-block" %> <% end %>
<%= render partial: "shared/aircrafts-list" %>
listing index.js.erb $("#aircraft_listing").html("<%= j render partial: 'shared/aircrafts-list' %>"); Works like a dream. Pages controller which won't play ball. Search works but not ajax call pages#home def home @search = Listing.ransack(params[:q]) if params[:search].present? @data = @search.result(:distinct => true) @listings = @data.to_a end end pages home.html.erb <%= search_form_for @search, remote: true do |f| %> <%= f.search_field: title_or_content_or_aircraft_highlights_or_airframe_engine_apu_weight_or_avionics_connectivity_or_interior_or_exterior_or_additional_info_cont, placeholder: "Search by keyword..", class: "form-control-lg form-control-borderless" %> <%= f.submit "Search", class: "btn btn-secondary btn-lg" %> <% end %>
<%= render partial: "shared/home-search-list" %>
pages home.js.erb $("#home_search_list").html("<%= j render partial: 'shared/home-search-list' %>"); alert('Hello Rails'); obviously alert doesn't pop up when search ran. Partials are named (have just checked them again to make sure i'm not going insane) _aircrafts-list.html.erb _home-search-list.html.erb And then the final bit where I can see the remote clearly not happening in the home page version. For some reason the form tag is not appearing in the home page example. I've just noticed this part now after the morning of pulling whats left of my hair out. Fresh eyes would be great. Now one other thing regarding Ransack, The fact my routes have resources for listing but i literally have just the root_path connected to my pages controller home action, does this matter with Ransack? Thanks all. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
So apologies all. I actually figured this out. See comments. Was already a reference to form tag so it made the Ransack form call redundant (Doing this with another developer so didn't notice the form tag above in the pages code. Silly stuff by me). When I removed this style I could see the remote call working. However it was still calling the data from the listings controller. I just needed to change the variable to something else @q and then also added the url path option to the form like below. Thanks everyone for reading. Apologies for the waste of time. Sometimes it just takes writing the whole thing down to realise how stupid you're being. Suppose can be used as a reference for other people going forward. <%= search_form_for @q, url: root_path, remote: true do |f| %> Allowed me to reference the root_path with the Ransack functionality.

Related questions

0 votes
    I have followed through some of the threads discussing ouput escaping in XSLT but none seesm to address the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I have followed through some of the threads discussing ouput escaping in XSLT but none seesm to address the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I have a rails application which is api only i am using gem rails-api. Now I am trying to create ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 26, 2022 in Education by JackTerrance
0 votes
    I would like to change the user sign-in behaviour of devise in a way to redirect a user to a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    When does the browser stop rendering the HTML? (a) Inline JavaScript block (b) External JavaScript file (c ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I was trying to write a quick-and-dirty script to generate plots easily. For that, I was using the following code ( ... do I do that? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    What is the HTML tag under which one can write the JavaScript code? A) B) C)
    While running the server, i am getting the error incompatible library version.Already Nokogiri is installed in ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    Trying to install the RMagick gem is failing with an error about being unable to find ImageMagick libraries, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    I'm trying to import an XML file via a web page in a Ruby on Rails application, the code ruby ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I have several properties that are dependent on the environment the application is running. For example, there ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    I have a text file, by which I am trying to write to in my program. Whenever user wants to add ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    Can we use JSON instead of YAML while developing docker-compose file in Docker?...
asked Jun 21, 2021 in Technology by JackTerrance
...