1

我在我的 rails 应用程序中使用 mustache 模板与mustache-rails 。我想做脚手架并使用 form_for 助手,但我无法让提交按钮工作。我找到了这个https://gist.github.com/954994,但我不想这样做太笼统。我只是想把我的脚手架变成一个基于模板的版本。

这是我的视图类

module Views
  module Slideshows
    class New < Layouts::Application

       def form
         form_for(@slideshow) do |f|
          {
              :submit => f.submit
          }
         end
       end

       def errors?
           @slideshow.errors.any?
       end

       def error_header
           "#{pluralize(@slideshow.errors.count, "error")} prohibited this post from being saved:"
       end

       def errors
         @slideshow.errors.full_messages
       end

       def back_link
         link_to 'Back', slideshows_path
       end  

    end
  end
end

这是我的模板类

<h1>New slideshow</h1>

{{#form}}
  {{#errors?}}
    <div id="error_explanation">
      <h2>{{error_header}}</h2>
    </div>
    <ul>
      {{#errors}}
        <li>{{.}}</li>
      {{/errors}}
    </ul>
  {{/errors?}}
  <div class="actions">
    {{submit}}
  </div>
{{/form}}

{{back_link}}

在我看来,问题是我无法在 form_for 块中访问 :submit 。

4

0 回答 0