Tabs not redirecting in jQuery UI tabs

限于喜欢 提交于 2019-12-08 13:33:26

问题


please help with rails 3 form in jquery ui tab.

This is the view(:controller => "pages", :action => "board") and form in the jquery tabs(form is in 2nd tab)

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Information:</a></li>
        <li><a href="#tabs-2">Form:</a></li>
    </ul>
    <div id="tabs-1">
        <p>info</p>
    </div>
    <div id="tabs-2">
        <% if @message.errors.any? %>
            <% @message.errors.full_messages.each do |msg| %>
               <li><%= msg %></li>
            <% end %>
        <% end %>
        <%= form_tag(:controller => "messages", :action => "create") do %>
              <%= label(:message, "Message:") %>
              <%= text_field_tag(:message) %>
              <%= submit_tag("Create Message") %>
        <% end %>
    </div>
</div>

In my controller i have:

def board
    @message = Message.find(:first, :conditions => ["id = ?", params[:message]])
end

def create
    @message = Message.new(params[:message])
    if @message.save
        redirect_to(:controller => "pages", :action => "home")
    else
        redirect_to(:controller => "pages", :action => "board", :id => "tabs-2", :message => @message.id)
end

I have the following problem:

If form parameters do not meet the model requirements it should redirect to tabs-2 and render parameters, instead it redirects to tabs-1.

Any help will be greatly appreciated. Thanks in advance.


回答1:


You need to define your selected tab in jquery while initializing your tabs:

$( "#tabs" ).tabs({ selected: $("#tabs").data("selected") });

in your view:

<div id="tabs" data-selected="<%= params[:selected] || 1 %>">
  ...
</div>

in your controller:

if @message.save
  redirect_to(:controller => "pages", :action => "home" )
else
  redirect_to(:controller => "pages", :action => "board", :selected => "2", :message => @message.id)
end


来源:https://stackoverflow.com/questions/5442628/tabs-not-redirecting-in-jquery-ui-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!