ruby on rails - who changed the value of "params[:tab]"? -
in 1 erb
file called x.html.erb
, confused following little snippet code:
<% params[:tab] |= "excursion" %> <% availablemodels.each |modelname| %> <% if modelname == "excursion" %> <li class="<%= params[:tab]=='excursions' ? 'active':''%>"> <a id="excursions_tab" href="#tabexcursions" data-toggle="tab"> excursions </a> </li> <% elsif modelname == "workshop" %> <li class="<%= params[:tab]=='workshops' ? 'active':''%>"> <a id="workshops_tab" href="#tabworkshops" data-toggle="tab">workshop </a> </li> <% end %>
i found can not figure out how params[:tab]
changed such params[:tab] = 'excursions'
to params[:tab] = 'workshops'
, or vice versa, or said changes value of params[:tab]
when toggle 1 tab excursion
or workshop
corresponding html:
<li class="active"> <div id="tab_excursions"> ...</div> </li> <li class> <div id="tab_resources"> ... </div> </li>
or
<li class> <div id="tab_excursions"> ...</div> </li> <li class="active"> <div id="tab_resources"> ... </div> </li>
for finding answer, tried change params[:tab]
params[:tabx]
, found worked fine. , <%= params[:tab]=='excursions' ? 'active':''%>
, must relative 1 rails
's magic?
the params[:tab] not change after created. part of rails stub performs logic on page load assist creating markup. way can guarantee params[:tab] hash has been defined current code at,
params[:tab] |= "excursion"
|= assigns params[:tab] "excursion" if has not been set. current view params[:tab] equal "excursion". if either "excursion" or "workshop" show active on page load hash being set earlier snippet.
what have in elements data-toggle attribute groups 2 items under same parent node (i believe). bootstrap has javascript function within listens click on either of elements , toggles between 2 accordingly.
in short, bootstrap, js functionality. check out : http://getbootstrap.com/2.3.2/javascript.html#tabs, toggleable tabs
--
determining tab set active based on params[:tab] value. after that, whichever tab click on set active bootstraps js , css , describable link provided
Comments
Post a Comment