开发者

how to set custom tab in jquery ui and use with rails

I'm using jqueryUI for tabs on a page. I initialize it like below:

$("#tabs").tabs();

<div id="tabs">
    <ul>

      <li><a href="#tabs-4">Part A</a></li>
      <li><a href="#tabs-2">Part B</a></li>
      <li><a href="#tabs-5">Part C</a></li>
   </ul>
   <div id="tabs-4">
    .....
   </div>
   <div id="tabs-2">
    ....
   </div>
   <div id="tabs-5">
   ....
   </div>
</div>

I have 2 questions.

  1. H开发者_JS百科ow do I set the tab to be custom. say I want second tab to be shown first. $('#tabs').tabs(2) does not work. i got that from this link

  2. Let say I click on a button inside tab1. Clicking on the button takes control back to an action and then control comes back to this page. When the control comes back...then is it possible to set a custom tab?. For example. in tab 1 I click something...go back to the action...and then I want to come back to tab 2.


This is one way I'd do it:

Controller:

before_filter :set_default_tab

def some_action
  @tab = "tab-3" # Go to a specific tab when using this action
  ...
end

private
  def set_default_tab
    @tab = params[:tab].blank? ? 'tab-1' : params[:tab]
  end

View:

# Use @tab in the view to set the current tab
<li class="<%= @tab == 'tab-1' ? 'active' : ''%>"><a>Tab 1</a></li>

# Add the :tab param to any path so the before filter sets @tab
go_do_some_action_path(@item, :tab => 'tab-2')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜