表单中的Button_to标记关闭表单
我目前正在使用ruby on rails 3中的表单。因此,在我的项目表单中,我有一个按钮,可以在此项目中签署用户。 然而,奇怪的是, button_to
标签关闭了我的整个表单,我不能再使用我的提交按钮了。
所以我尝试了很多,但我不明白为什么会这样。
所以这是我的forms:
'control-label', style: 'margin-bottom: 20px' %> 'btn btn-primary' %> t("helpers.links.cancel")), projects_path, :class => 'btn btn-default' %>
在我看来,这个代码看起来很好,因为所有标签都完全关闭。 但是,我认为使用button_to
时可能会有一些魔力,所以也许有人知道更好的方法来做我想做的事情。
谢谢!
不要在表单中放置button_to
。
根据文档 :
(
button_to
)生成一个包含单个按钮的表单,该按钮提交到由该组选项创建的URL
–
HTML表单有一个明确的规范 ,每当你实现它时你都应该遵守它。
在表单中包含表单会导致“外部”表单停止工作(HTML无法在之前处理另一个
。
简单的答案是从表单中删除button_to
并将其放在外面, 或者 (在您的情况下),将其替换为另一个元素( link_to
)。 如果您希望链接看起来像一个按钮,您可以使用标记来创建一个按钮:
<%= form_for @project, html: { class: "form-horizontal project" } do |f| %> <%= f.label :users, 'Project Users:', :class => 'control-label', style: 'margin-bottom: 20px' %> <% @project.users.order('last_name').each do |user| %> <%= user.name %> <%= link_to ''.html_safe, sign_user_out_project_path(user_id: user.id, id: @project), method: :delete, class: 'btn btn-danger btn-xs pull-right', style:'margin-right: 600px; margin-top: -20px' %> <% end %> <%= f.submit nil, :class => 'btn btn-primary' %> <%= link_to t('.cancel', :default => t("helpers.links.cancel")), projects_path, :class => 'btn btn-default' %> <% end %>