ruby - Rails rendering locals to partials in a loop and accessing them -


hi want make game application users can participate in games , can create teams. here code in games_controller.rb

def team_events   @doubles = game.where(game_type: game::doubles)   @mixed_doubles = game.where(game_type: game::mixed_doubles)   @others = game.where(game_type: game::others) end 

code in team_events.html.erb:

<div class = "container-fluid">   <div class = "row">     <%= render partial: "shared/table", locals: {doubles_games: @doubles} %>   </div> </div> 

in below partial show link "create team" beside every game. when user clicks modal dialog opens contains form create team. enter image description here

code in _table.html.erb partial

<table class = "table table-hover">    <thead>     <tr>       <th> game </th>       <th> game type </th>       <th> actions </th>    </tr>   </thead>    <tbody>     <% doubles_games.each |game| %>       <tr>         <td><%= game.name %></td>         <td><%= game.game_type %></td>         <td>           <a href="#" type="button" data-toggle="modal" data-target="#mymodal">           create team           </a>         </td>       </tr>     <% end %>   </tbody>  </table> 

bootstrap modal window

<div class="modal fade" id="mymodal" role="dialog">   <div class="modal-dialog">     <div class= "modal-content">        <div class="modal-body">         <%= render partial: 'teams/form', locals: {game: game} %>       </div>      </div>   </div> </div> 

code in _form.html.erb

<%= simple_form_for team.new, url: teams_path(game_id: game.id), method: :post |f| %>   <%= f.input :game_name, label: "game", input_html: {value: "#{game.name}"}, disabled: true %>   <%= f.input :game_type, label: "type", input_html: {value: "#{game.game_type}"}, disabled: true %>   <%= f.input :name, autofocus: true, required: false, hint: "name team" %>   <%= f.input :members, as: :text, required: true, hint: "enter names seperated comma" %>   <%= f.submit "create", class: "btn btn-success" %> <% end %> 

when user clicks "create team" link beside game, modal window opens , form create team appears. in modal window game user creates team appear(check disabled: true option in _form.html.erb). when click on create team of table tennis. following window appears

enter image description here

here problem game user clicks on create team link, shows same game. if click create team badminton or carrom. in window showing table tennis please let me know if need more details

you have id 'mymodal' , data-target="#mymodal" games. opening first modal id 'mymodal'. id must unique in document. try use different id each modal fix issue.

you having many forms (inside loop), can trigger modal javascript , pass game type or id avoid more html content.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -