In my application I have a Gallery class and a Project class, which are connected with a has_and_belongs_to_many
relationship. I'm trying to add the ability to add projects to a gallery, using a dropdown select with all of the current projects in the database populated as options. My form for creating a new gallery is the following:
<%= 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 %>
However, when I go to the new gallery page, I get the following error
Formtastic::UnknownInputError in Galleries#new
Showing /app/views/galleries/_form.html.erb where line #4 raised:
Unable to find input class for select
I tried to follow the specifications as defined in the documentation, so why am I getting this error? Do I need to add something to my galleries_controller.rb?
Edit - Here are both of the models
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
It turns out that this is a problem with gem versions between Formtastic and Formtastic-bootstrap. According to this issue:
formtastic-bootstrap 3.0 actually only support formtastic 2.x.
I was using Formtastic version 3.x so downgrading to Formtastic 2.x solved my problem. This is how I updated my Gemfile:
gem 'formtastic', '~> 2.0'