0

I have started to use Rails_Admin gem and it is great. However, there is one issue. I am using Mongoid and I have created my models:

class Client
   include Mongoid::Document

   field :email, type: String

   has_many :favourites, dependent: :destroy
end

class Service
   include Mongoid::Document

   field :name, type: String
   has_many :favourites, dependent: :destroy
end

class Favourite
   include Mongoid::Document

   belongs_to :client
   belongs_to :service
 end

I have created some data by using seed.rb. When I open my admin page and try to create new Client, after Clients attribute fields, it shows me multiselect form to add Favourites and shows me Favourites of all other Clients.

How to remove this from creation form? I have read that I need to add inverse_of for all my classes associations, but it is not removing them.

1 Answer 1

1

In your model:

class Client
    include Mongoid::Document
    field :email, type: String
    has_many :favourites, dependent: :destroy

    rails_admin do
     edit do
       exclude_fields :favourites
     end
    end
end

Source: https://github.com/sferik/rails_admin/wiki/Railsadmin-DSL#configuring-fields

Sign up to request clarification or add additional context in comments.

2 Comments

throws me an error NoMethodError undefined method default for #<Client:0x0000000d569598>
This solution brings new question. I have removed nested form during the creation of model. If I want to something like add Favourite for this Client in edit page of my model, what do I need to do?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.