在jQuery UI选项卡中不重定向的选项卡

时间:2022-10-06 20:40:26

please help with rails 3 form in jquery ui tab.

请在jquery ui选项卡中帮助处理rails 3表单。

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

这是jquery选项卡中的视图(:controller =>“pages”,:action =>“board”)和表单(表单在第二个选项卡中)

<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.

如果表单参数不满足模型要求,它应该重定向到表2并呈现参数,而不是重定向到表1。

Any help will be greatly appreciated. Thanks in advance.

如有任何帮助,我们将不胜感激。提前谢谢。

1 个解决方案

#1


1  

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

在初始化选项卡时,需要使用jquery定义所选选项卡:

$( "#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

#1


1  

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

在初始化选项卡时,需要使用jquery定义所选选项卡:

$( "#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