【问题标题】:Error while updating a record using Formtastic in HAML templates在 HAML 模板中使用 Formtastic 更新记录时出错
【发布时间】:2010-03-02 12:13:02
【问题描述】:

我在 HAML 表单中使用 formatastic

- semantic_form_for @company do |f|
  - f.inputs do
    = f.input :description 
    = f.input :type 
    = f.input :industry 
    = f.input :hq 
    = f.input :products 
    = f.input :subsidiaries 
    = f.input :employees 
    = f.input :revenue 
    = f.input :net_income 
  = f.buttons 

当我尝试保存现有记录时,我得到一个错误。

Template is missing
Missing template companies/update.erb in view path app/views

我最近将表单从 ERB 迁移到 HAML。用于 ERB 的表单。

我该如何解决这个问题?

编辑

我解决了这个问题。它与 HAML 或 Formtastic 无关。我将一个块传递给save 方法,这导致了问题。有关详细信息,请参阅下面的答案。

【问题讨论】:

    标签: ruby-on-rails ruby formtastic


    【解决方案1】:

    您是否为 Haml 安装了 Rails 插件?

    【讨论】:

      【解决方案2】:

      我找到了这个错误的原因。我在另一个使用 OAuth 插件的项目中重用了控制器中的一些代码。 OAuth 插件要求您将块传递给 ActiveRecord save 方法。 vanilla ActiveRecord save 不支持块。一旦我删除了块,一切正常。 原代码:

        def update
          @company.attributes = params[:company]
          @company.save do |result|
            if result
              flash[:notice] = "Successfully updated company."
              redirect_back_or_default root_url
            else
              render :action => 'edit'
            end
          end
        end
      

      一些参考资料:

      Article 1

      Article 2

      【讨论】:

        【解决方案3】:

        Rails 正在 app/views/companies/ 中寻找一个名为 update.something.erb(可能是 update.html.erb)的视图文件。我猜你有一个 update.html.haml 文件,所以这就是你收到错误的原因。

        无论如何,这与Formtastic无关。

        您在 app/views/companies 中列出了哪些文件?

        【讨论】:

        • 我解决了这个问题。它与 HAML 或 Formtastic 无关。我正在将一个块传递给 save 方法,这导致了问题。有关详细信息,请参阅我的答案。
        猜你喜欢
        • 2018-12-17
        • 1970-01-01
        • 1970-01-01
        • 2010-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-08-24
        • 1970-01-01
        相关资源
        最近更新 更多