javascript - Trying to Perform Live AJAX Search in sidebar -
I am new to AJAX searches and am quite new to the rail. I'm trying to create a search form in my app's sidebar so that it is included on every page. I need search results, when a search is currently entered.
I have 'movies' tables and I am just starting my search for the 'title' column. Here is what I have so far. Search is not returning to search results just in the div, nor is it returning any results on the current page. Use of Rail 4.0.0.
_sidebar.html. ARB movies_controller.rb movie.rb _cresults.html. ARB movies.js movies.js.erb I also tried putting the same code from movies.js to application.js but the result There was no change in the guests. So I was able to understand it. Can help, but what I am changing here: movies .js Application.js - This has been removed which only caused the AJAX search to work on the index page There are index.js.erb _sidebar.html. The ARB file has changed slightly:
& lt; One side ID = "sidebar" & gt; & Lt; NAV & gt; & Lt;% = form_tag movies_path ,: method = & gt; 'Go',: id = & gt; "Movies_search"% & gt; & Lt; Center & gt; & Lt; P & gt; & Lt;% = text_field_tag: search, parameter [: search]%> & Lt;% = submit_tag "Search",: name = & gt; Zero% & gt; & Lt; / P & gt; & Lt; / Center & gt; & Lt; Div id = "cresults_div" style = "float: right; width: 300px;" & Gt; & Lt;% = Renderer 'cresults'% & gt; & Lt; / Div & gt; & Lt;% end% & gt; & Lt; UL style = "margin-top: 300px;" & Gt; & Lt; Li class = "all-movies" & gt; & Lt;% = link_to 'All movies', movies_path, class: 'button'% & gt; & Lt; / Li & gt; & Lt; Li class = "built-movie" & gt; & Lt;% = link_to 'Add new movie', new_movie_path, category: 'button'% & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Neo & gt; & Lt; / One side & gt;
DIF index @ movie = movie. Release @ Movie = Movie Search (Param [: Search]) End End
def self.search (search) if Is the search, where ('like the title?', "% # {Search}%") and otherwise the ending
& lt; H2 & gt; Search Results: & lt; / H2 & gt; & Lt; Table & gt; & Lt; TR & gt; & Lt; Th & gt; Title: & lt; / Th & gt; & Lt; Th style = "width: 85px;" & Gt; Issued: & lt; / Th & gt; & Lt; Th & gt; Rating: & lt; / Th & gt; & Lt; / TR & gt; & Lt;% @ movies.each do | Movie | & Gt%; & Lt; TR & gt; & Lt; Td> & Lt;% = link_to movie.title, movie% & gt; & Lt; / Td> & Lt; Td> & Lt; Center & gt; & Lt;% = movie.released_on.year% & gt; & Lt; / Center & gt; & Lt; / Td> & Lt; Td> & Lt; Center & gt; & Lt;% = movie.rating%> & Lt; / Center & gt; & Lt; / Td> & Lt; / TR & gt; & Lt;% end% & gt; & Lt; / Table & gt;
$ (function () {$ ('# movies_search'). Submit (- & $ {. (Action. $ (This). Certificate (), empty, 'script') false}}; $ (function () {$ ('# movies_search input') .keyboard (- & gt; $. ("# Movies_search") ARTR ("Action"), $ ("# movies_search"). Serialize (), empty, 'script') false}}}};
$ ("# cresults_div") .HTML ("& lt;% = escape_javascript (render (" cresults ")% Gt; ");
$ (function () {$ (' # Movies_search input '). Key (function () {if ($ (this) .val (). Length & lt; 1 & amp; Amp; Ekeykey! = 13) returns; $ .gate ($ ('# movies_search'). Entry ('Action'), $ ('# movies_search'). Liz (), blank, 'script'); return false; }); ATR ('Action'), $ ('# movies_search'). $ $ $ (Function () {$ ('function') ($ ('button').), Blank, 'script'); Return false;});}
$ ("#Cresults_div"). Html ("& lt;% = escape_javascript (render ('cresults'))%>;);
Comments
Post a Comment