So, I have the following models in my program:
class User < ActiveRecord::Base has_many :group_members has_many :groups, through: :group_members class GroupMember < ActiveRecord::Base belongs_to :user belongs_to :group end class Group < ActiveRecord::Base has_many :group_members has_many :users, through: :group_members end
And I use ActiveAdmin to administer these resources. My groups.rb file in the admin folder looks like this:
ActiveAdmin.register Group do . . belongs_to :user, :optional => true . . end
The problem is that Group is a resource in itself - an administrator can manage groups by going to the /admin/groups route, but it is also a user resource, and I can browse user groups by accessing /admin/users/:user_id/groups route. However, when I try to create a new group for this user, by accessing the /admin/users/:user_id/groups/new page and filling out the form, I get an error message:
ActiveRecord::RecordNotFound in Admin::GroupsController
The user ID corresponds to my currently registered user, and this is correct, while the group identifier = 13 corresponds to the identifier of the newly created group (it is correctly stored in the database), but the association in the group_members table is not created. Actually, this is not even what I am trying to achieve here: the ideal scenario would be to get a list of groups and display it on a new page so as not to create new groups on this page - only group_members .
How can I continue in this case? Thanks in advance!
source share