我该如何在Rails中使下拉列表重定向到另一个包含特定信息的页面

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

本文关键字:包含特 另一个 信息 重定向 下拉列表 Rails      更新时间:2024-02-17

我的index.html.erb页面中有一个英文字母a->Z的下拉列表,带有Select All选项。我的解析器从.txt中获取特定的单词,并在索引页面中显示这些单词。我想在选择一封只有以该字母开头的单词的信件后组织页面。

我是Rails的新手;考虑到这一点,我想使用AJAX,这样信息就可以显示在同一个页面上。

考虑到这些,我不确定如何最好地取得进展;使用JavaScript、erb等。到目前为止,我还没有实现任何代码,我正在寻找想法。

  • 使链接成为远程链接:link_to "A", index_path(letter: "A"), remote: true
  • 在索引操作中加载单词:@words = Word.where("word ILIKE ?", "#{params[:letter]}%")
  • 并响应JS请求:respond_to { |format| format.js }
  • index.js.erb中,将单词呈现到页面中:$("#wordlist").html("<%= escape_javascript(render('words', words: @words)) %>");
相关文章: