1

formatastic以 HAML 形式使用。

- 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这导致了问题。有关详细信息,请参阅下面的答案。

4

3 回答 3

1

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

于 2010-03-02T16:51:10.133 回答
1

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

  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

一些参考资料:

第1条

第二条

于 2010-03-02T20:37:14.927 回答
0

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

无论哪种方式,这与Formtastic无关,抱歉。

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

于 2010-03-02T19:39:26.710 回答