1

我有一个运行良好的验证的 SimpleForm 设置。我现在想实现 AJAX,所以我不需要执行页面重新加载。当我添加:remote => true到我的代码中时,验证不再起作用。这是预期的行为吗?当 remote 设置为 true 时,我的 SimpleForm 验证是否应该不再起作用?

这是我的代码示例:

<%= simple_form_for @business, :url => {:action => "create", :id => "submit_subscription_signup_form"}, :html => {:class => "form-horizontal"}, :remote => true do |f| %>

  <% if notification = f.error_notification %>
    <div class="alert alert-error fade in">
      <a class="close" data-dismiss="alert" href="#">&times;</a>
      <%= notification %>
    </div>
  <% end %>

  <%= f.input :business_name, :input_html => { :class => "span6" } %>
  <%= f.input :address1, :input_html => { :class => "span6" } %>
  <%= f.input :city, :input_html => { :class => "span6" } %>

  <div class="actions" style="text-align: right;"><%= f.submit "Sign Up", :class => 'btn btn-success', :id => "signup_form_submit_button" %></div>
<% end %>

我在控制器中的创建操作:

def create
@business = Business.new(params[:business])
if @business.save 
  #removed logic for simplicity
  respond_to do |format|
    format.html
    format.js { render 'subscriptions/_logged_in' }
  end
else
  respond_to do |format|
      format.html { render 'index' }
      format.js { render 'subscriptions/_signup' }
   end
end
end  

并且看到我希望提交失败并显示验证,然后我的 _signup.js.erb 部分将被调用。主视图包含许多通过 jQuery 显示或隐藏的表单。所以 _signup.js.erb 包含:

$('#login_form').hide()
$('#logged_in_form').hide()
$('#signup_form').show()
4

0 回答 0