私が達成しようとしている目標は、ユーザーがボタンをクリックしてそのページのフィルタを検索するようにすることです。私のページは音楽アーティストに専念していて、ユーザーが「ポップ」を選択すると、そのページは「ポップ」アーティストのみを表示するように更新されます。ここでRails - 新しいテーブルエントリを持つページを更新する
は、私は、アーティストを表示するために使用していますHTML +ルビー:
<% #prints the artists that match the search, prints all for empty search %>
<% @artists.each_slice(3) do |artists| %>
<div class="row">
<% artists.each do |artist| %>
<div class = "artist_images">
<%= link_to image_tag(artist.artist_art, class: 'show_image'), artist_path(artist) %><br/><br/>
</div>
<% end %>
</div>
<% end %>
<% #prints message showing that the search does not match %>
<% if [email protected]? %>
<h3><center style = "color: white">There are no artists containing the term(s) "<%= params[:search] %>". Please try 'Adele', 'Drake', 'Kanye West', or 'Taylor Swift'</center></h3>
<% end %>
コントローラは、次のメソッドがあります。
def index
@artists = Artist.all
end
def randomPop
@artists = Artist.where(:genre => "\nPop").random(9)
end
誰も私が変更について行くことができる方法を知っています変数@artists
からすべてのアーティストまで、ボタンをクリックするだけでポップスのアーティストに変換できますか?
私はあまりよく分からないただし、Fayeのような別のサーバーを使用して、WebSocketでデータを動的に要求する必要があります(非同期アプリケーション(チャットアプリなど)と同じように)。または、AJAXを使用します。 – EvilTak
ページ全体をAJAXyの方法でリフレッシュまたは実行しますか? –
@Petr Gazarov、ページはかなり小さいので、リフレッシュ全体が細かいでしょう。 – QQPrinti