simple_form associations and mongomapper
-
13-11-2019 - |
Question
I get this message when I try to add an association in my form:
Association :role not found
role.rb
...
many :users
key :name, String
key :description, String
...
user.rb
...
belongs_to :role
key :username, String
key :password, String
key :password_salt, String
key :email, String
key :first_name, String
key :last_name, String
key :active, Boolean, :default => true
...
form
<%= simple_form_for [:admin, @user] do |f| %>
<%= f.input :username %>
<%= f.input :email %>
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :password %>
<%= f.association :role %>
<%= f.input :active, :as => :boolean %>
<%= f.button :submit %>
<% end %>
Has anyone used associations in simple_form with mongomapper?
Solution
For now, simple_form only works with active_record. But if you want to use it with any active_model compatible library, make sure that you have passed the collection to association helper. eg.:
<%= f.association :role, :collection => Role.all %>
But I think that mongomapper is not an active_model compatible library.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow