2014-11-09 54 views
1

在我的应用程序中,我有一个Gallery类和一个Project类,它们与has_and_belongs_to_many关系有关。我正在尝试添加将项目添加到图库的功能,使用下拉选择将数据库中的所有当前项目填充为选项。我创建一个新的画廊格式如下:Formtastic未知输入错误 - 找不到输入类别

<%= 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 
+0

你可以添加这两种车型在这里 – Hemali 2014-11-09 08:54:24

+0

@Hemali我加入他们 – KJ50 2014-11-09 19:41:46

+0

尝试。 '<%= f.input:project:as =>:select,:collection => Project.all, :include_blank => true,:input_html => {:multiple => true}%>' – Hemali 2014-11-10 11:43:28

回答

1

的事实证明,这是Formtastic和Formtastic自举之间的宝石版本中的问题。根据this issue

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

我使用Formtastic版本3.x,所以降级到Formtastic 2.x解决了我的问题。这是我更新了我的Gemfile:

gem 'formtastic', '~> 2.0'