I have a view with three checkboxes:
<div class="tourny-games">
<h4>Games</h4>
<div class="checkboxOptions games show-tabs">
<div class="show-tab">
<div class="checkbox uncheckBoxed">
<input id="" name="" onclick="toggleCheckboxImage(this, '');" type="checkbox" value="1" />
</div>
<img src="https://s3.amazonaws.com/...iconlol.png.jpg" class="game-logo-label" />
</div>
# two more checkboxes here
</div>
</div>
which create tabs:
<div class="tabs">
<% @games.each do |game| %>
<a href="#<%= game.striped_name %>" game="<%= game.id %>" game-type="<%= Game::TEAM_GAMES.include?(game.name) ? "team" : "single" %>" class="tab" style="<%= "display:none;" unless @tournament.game_ids.include?(game.id) %>">
<%= game.name %>
</a>
<% end %>
</div>
via this jquery:
$('.show-tabs .show-tab').live('click', function(){
var tab = $('.tabs .tab:nth-of-type(' + ( $(this).index() + 1 ) + ')');
...
if ($(this).find('.checkbox').hasClass('checkBoxed')){
tab.show();
...
} else {
tab.hide();
}
});
Based on this answer, I have the following code to set @game_type
controller:
def game_type
@game_type = params[:game_type]
end
jquery:
if ($(this).find('.checkbox').hasClass('checkBoxed')){
tab.show();
$.get('tournaments/game_type?game_type='+tab.attr("game-type"))
I've tested tab.attr("game-type") with alert so I know it's pulling the variable I want - it returns either team or single - but I need to do some conditional checking in other rails code further down the page - how can I do that?
for example, this pseudocode demonstrates one of the things I'd need to do:
if @game_type == "team"
"Team Name"
else
"Player Name"
end
I know that the @game-type variable is loaded with Rails, and therefore would just be blank - but that's where the AJAX comes in, and that's also where I'm a bit confused. This question seems pertinent to what I'm asking, but it's different enough that I can't seem to get it working in my own code.