我有一些rails应用程序,但我的submit
按钮不会触发任何内容。 (我使用twitter bootstrap)。这是tag
<input class="btn btn-info" type="submit" value="Sign up" name="commit">
当我点击它时,没有任何反应。也许bootstrap
中有一些“防止默认”方法,但我该如何调试呢?
<form accept-charset="UTF-8" action="/users" class="panel-body" data-validate="true" id="new_user" method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="TOWfy1DjcfzzIoCe/BYdEfsKf5gyW902uiyAZxq2GVw="></div>
<div class="block">
<label class="control-label" for="user_user_name">User name</label>
<input class="form-control" id="user_user_name" name="user[user_name]" placeholder="username" type="text" data-validate="true">
</div>
</a> <input class="btn btn-info" type="submit" value="Sign up" name="commit">
<div class="line line-dashed"></div>
<div class="row">
<div class="col-sm-6 text-center">
<a href="#" class="btn btn-facebook btn-circle btn-sm"><i class="icon-facebook"></i>Sign up with Facebook</a>
</div>
<div class="col-sm-6 text-center">
<a class="btn btn-twitter btn-circle btn-sm" href="/users/auth/twitter">
<i class="icon-twitter"></i>Sign up with Twitter
</a> </div>
</div>
<div class="line line-dashed"></div>
</form>
我的rails代码(上面的代码基本上是后面的产品,我删除了不必要的inputs
):
<%= form_for(resource, :as => resource_name, :validate => true, :html => {:class => "panel-body"}, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="block">
<%= f.label :user_name, :class=>"control-label"%>
<%= f.text_field :user_name, :autofocus => true, :placeholder=>"username", :class=>"form-control" %>
</div>
<div class="block">
<%= f.label :email, :class=>"control-label"%>
<%= f.email_field :email, :autofocus => true, :placeholder=>"email", :class=>"form-control" %>
</div>
<div class="block">
<%= f.label :password, :class=>"control-label"%>
<%= f.password_field :password, :autofocus => true, :placeholder=>"password", :id=>"inputPassword", :class=>"form-control" %>
</div>
<div class="block">
<%= f.label :password_confirmation, :class=>"control-label"%>
<%= f.password_field :password_confirmation, :autofocus => true, :placeholder=>"confirm password", :id=>"inputPassword", :class=>"form-control" %>
</div>
<div class="checkbox">
<label>
<%= f.check_box :terms_of_service, {}, true, false %> Agree the <%= link_to "terms and policy" %>
</label>
</div>
<%= link_to dees_path, :class=>"pull-right m-t-mini" do%>
Forgot password? <%= content_tag(:small, "", :class => "") %>
<% end %>
<%= f.submit "Sign up", class:"btn btn-info" %>
<div class="line line-dashed"></div>
<div class="row">
<div class="col-sm-6 text-center">
<a href="#" class="btn btn-facebook btn-circle btn-sm"><i class="icon-facebook"></i>Sign up with Facebook</a>
</div>
<%= render "devise/shared/connect_social_links" %>
</div>
<div class="line line-dashed"></div>
<% end %>
答案 0 :(得分:0)
第一步是确保您的应用程序实际上正在接收“提交”呼叫。如果不是,那么这是你的HTML表单的问题,如果是,那么你使用Rails定义表单的方式就会出现问题
这就是我要做的事情:
#app/assets/javascripts/application.js
$(document).on('submit', '.panel-body', function(e) {
e.preventDefault();
alert('submit');
});
这允许您查看提交功能是否实际触发。之后,您将能够判断是否是导致问题的表单数据本身。
当我看到你正在使用Devise时,你可能没有正确定义form_for
个变量。如果您尝试我发布的建议,然后在评论中回复它的表现,我将处于更有利的位置来帮助您