Formtastic未知输入错误 - 无法找到select的输入类

时间:2014-11-09 08:11:25

标签: ruby-on-rails ruby-on-rails-4 formtastic

在我的应用程序中,我有一个Gallery类和一个Project类,它们与has_and_belongs_to_many关系相关联。我正在尝试添加将项目添加到库中的功能,使用下拉选择,将数据库中的所有当前项目填充为选项。我创建新图库的表单如下:

<%= semantic_form_for @gallery do |f| %>
  <%= f.inputs do %>
    <%= f.input :title %>
    <%= f.input :projects, :as => :select, :collection => Project.all,
                :include_blank => true, :input_html => { :multiple => true } %>
  <% end %>

  <%= f.actions do %>
    <%= f.action :submit, :as => :input %>
  <% end %>
<% end %>

但是,当我转到新的图库页面时,我收到以下错误

Formtastic::UnknownInputError in Galleries#new
Showing /app/views/galleries/_form.html.erb where line #4 raised:
Unable to find input class for select

我尝试按照in the documentation定义的规范,为什么我会收到此错误?我需要在galleries_controller.rb中添加一些内容吗?

编辑 - 这是两个模型

class Gallery < ActiveRecord::Base
  has_and_belongs_to_many :projects
  belongs_to :user
  validates :title, uniqueness: true
  validates :title, length: { minimum: 4 }
  validates :user, presence: true
end

class Project < ActiveRecord::Base
  belongs_to :user
  has_many :comments
  has_and_belongs_to_many :galleries

  validates :title, presence: true
  validates :thumbnail, presence: true

  def root_comments
    comments.where parent_id: nil
  end
end

1 个答案:

答案 0 :(得分:1)

事实证明,这是Formtastic和Formtastic-bootstrap之间的宝石版本的问题。根据{{​​3}}:

  

formtastic-bootstrap 3.0实际上只支持formtastic 2.x。

我使用的是Formtastic版本3.x,因此降级为Formtastic 2.x解决了我的问题。这是我更新我的Gemfile的方式:

gem 'formtastic', '~> 2.0'