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
你可以添加这两种车型在这里 – Hemali 2014-11-09 08:54:24
@Hemali我加入他们 – KJ50 2014-11-09 19:41:46
尝试。 '<%= f.input:project:as =>:select,:collection => Project.all, :include_blank => true,:input_html => {:multiple => true}%>' – Hemali 2014-11-10 11:43:28