【问题标题】:Simple form submit button not working when inside content_for简单的表单提交按钮在 content_for 中不起作用
【发布时间】:2013-04-24 19:30:57
【问题描述】:

我使用带有引导程序的简单表单在 Rails 中创建了这个表单:

<%= simple_form_for @page, :html => { :class => 'page-form' } do |f| %>
<div class="row">

    <%= f.input :title, wrapper_html: { class: 'span6'}  %>
    <%= f.input :url, wrapper_html: { class: 'span3'}  %>
    <%= f.input :content, input_html: { class: 'wysihtml5 span9' }, wrapper_html: { class: 'span9 row' } %>
    <%= f.input :excerpt, input_html: { class: 'wysihtml5 span9 excerpt' }, wrapper_html: { class: 'span9 row'}  %>

</div>

<% content_for :sidebar do %>
  <div class="page-header">
    <h1>Publish</h1>
  </div>
  <div class="well">
    <%= f.input :status , collection: Page::STATUS.map { |s| [s.humanize, s] }, prompt: '- Select page status -' %>
      <div class="form-actions">
        <%= f.button :submit, :class => 'btn btn-primary' %>
        <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
                    pages_path, :class => 'btn' %>
      </div>
  </div>

<% end %>

<% end %>

问题是当提交按钮位于content_for 块内时,它不会在单击时更新表单。如果我有这个块之外的按钮,它就可以工作。

有没有办法让它在content_for 块内部工作?我需要它在侧边栏中。

想要的结果图片:

感谢任何提示、答案或有用的 cmets :)

【问题讨论】:

    标签: ruby-on-rails forms simple-form


    【解决方案1】:

    我自己找到了答案。

    通过将表单元素放入侧边栏,当然可以将表单域呈现在表单标记之外。 (在页面底部,侧边栏的其余部分通过应用程序布局呈现)。

    这会导致表单域未附加到表单。

    我的解决方案是删除 content_for 块,并在这种情况下以部分形式处理侧边栏。

    【讨论】:

      猜你喜欢
      • 2015-10-10
      • 2016-09-18
      • 1970-01-01
      • 2013-12-17
      • 2016-11-21
      • 2020-10-08
      • 2020-08-21
      • 1970-01-01
      相关资源
      最近更新 更多