0

I have the following view in my rails app:

<div class="row">
  <div class="span11 center searchFieldContainer">
    <div class="span3">
        <%= collection_select :matchup, :player_1, Player.all, :id, :last_name, {}, { :multiple => false, class: "matchupSearchField", id: "player_1_search_field" } %>
    </div>
    <div class="span3">
        <h2>VS</h2>
      </div>
      <div class="span3">
        <%= collection_select :matchup, :player_2, Player.all, :id, :last_name, {}, { :multiple => false, class: "matchupSearchField", id: "player_2_search_field" } %>
    </div>
  </div>

  <%= link_to "View Matchup", 
    findMatchup_path(:player_1 => **ID_OF_PLAYER_1**, :player_2 => **ID_OF_PLAYER_1**),
    :method => :get, class: "my_class" %>
</div>

which is part of '/home.html.erb', my root_path.

How can I replace ID_OF_PLAYER_1 in the link_to with the ID of the player selected in the collection_select above? Can I use jQuery to get the value of that collection_select field?

Thanks!

4

1 に答える 1

0
<%= form_tag('/findMatchup', method: :get) do %>
    <div class="row">
    <div class="span11 center searchFieldContainer">
        <div class="span3">
            <%= collection_select :matchup, :player_1, Player.all, :id, :last_name, {}, { :multiple => false, class: "matchupSearchField", id: "player_1_search_field" } %>
        </div>
        <div class="span3">
            <h2>VS</h2>
          </div>
          <div class="span3">
            <%= collection_select :matchup, :player_2, Player.all, :id, :last_name, {}, { :multiple => false, class: "matchupSearchField", id: "player_2_search_field" } %>
        </div>
      </div>
    </div>
  <div class="row">
    <%= submit_tag "View Matchup", class: "btn" %>
  </div>
<% end %>

コントローラーは、以下を使用して変数にアクセスします。

@player1 = Player.find(params[:matchup][:player_1])
于 2013-09-27T00:03:29.407 に答える