简体   繁体   中英

How would I make a dropdown list redirect to another page with specific information in Rails?

I have in my index.html.erb page a dropdown list of the English alphabet, A->Z, with a Select All option. My parser takes specific words from a .txt and displays the words in the index page. I want to organize the page after a letter is selected with only words beginning with that letter.

I am new to Rails; with that in mind, I want to use AJAX so that the information just gets displayed on the same page.

With these in mind, I am not sure how best to progress; using JavaScript, erb, etc. As of now I currently have no code implemented and I am looking for ideas.

  • Make the links remote: link_to "A", index_path(letter: "A"), remote: true
  • Load the words in your index action: @words = Word.where("word ILIKE ?", "#{params[:letter]}%")
  • And respond to JS requests: respond_to { |format| format.js } respond_to { |format| format.js }
  • In your index.js.erb , render the words into the page: $("#wordlist").html("<%= escape_javascript(render('words', words: @words)) %>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM