Closed rpalackas closed 1 year ago
Accidentally submitted https://github.com/railsadminteam/rails_admin/issues/3557 before I finished writting it up so I closed it. Sorry for the duplicate
How do you configure RailsAdmin? Could you show me what you have in config/initializers/rails_admin.rb
and models ?
Rails admin config:
RailsAdmin.config do |config|
config.asset_source = :sprockets
config.main_app_name = ['Company', 'Admin']
config.current_user_method { current_user }
config.authorize_with :cancancan
config.parent_controller = 'RailsAdminController'
config.actions do
dashboard { statistics false }
send_grid_templates
generic_enrollment_file_upload
remove_proconnection_file_upload
on_board
admin_tools
index # mandatory
new do
except do
[VariousModels]
end
end
export
history_index
bulk_delete
# member actions
show
edit do
except do
[OtherModels]
end
end
delete do
except do
[MoreModels]
end
end
history_show
show_in_app
end
end
User model relevant rails admin bit:
class user
include RailsAdmin::User
belongs_to :primary_authorized_site, class_name: ProviderGroupSite.name,
inverse_of: :primary_authorized_sites
field :test_only, type: ::Mongoid::Boolean, default: false
has_and_belongs_to_many :authorized_sites,
class_name: ProviderGroupSite.to_s,
inverse_of: :users,
autosave: true,
validate: false
end
User rails admin concern edit portion:
module RailsAdmin::User
extend ActiveSupport::Concern
included do
rails_admin do
scope { abstract_model.scoped.unscoped }
list do
# various list fields here
end
show do
# various show configurations here
end
edit do
group :personal_info do
# various fields here
field :test_only do
label 'Test Only'
visible do
User.current_user.admin?
end
end
end
group :user_info do
# various fields here
field :primary_authorized_site
field :authorized_sites
end
end
end
end
end
Thanks for sharing. I think this will be the same issue with #3490.
Can you see if upgrading rails_admin to 3.1.0.rc2
helps?
@mshibuya Yep upgrading to 3.1.0.rc2 does resolve that issue. However on that tag my navigation is real screwy not sure if this is a known issue:
I won't be able to upgrade to a release candidate but I might be able to convince the team to enable eager_load temporarily and we'll upgrade to 3.1 as soon as it fully releases and disable that setting. Do you have a timeline on the 3.1 release?
Make sure that you use the latest RailsAdmin JS and CSS. Did you update the rails_admin
npm package?
@mshibuya no just updated the gem in my Gemfile. Not going to have a change to update the npm package. Thanks for your help this issue can be closed since it is resolved in 3.1
For anyone else who runs into this issue there are 2 ways it can be solved without upgrading to rails admin 3.1. The first is as I noted above to enable eager_load in your application configuration. The second is to move your include that adds rails admin configurations to after all of your relationship declarations. This causes the relationships to be loaded first then the rails admin config loads and correctly identifies the field types. So in my above example the user model would change to
class user
belongs_to :primary_authorized_site, class_name: ProviderGroupSite.name,
inverse_of: :primary_authorized_sites
field :test_only, type: ::Mongoid::Boolean, default: false
has_and_belongs_to_many :authorized_sites,
class_name: ProviderGroupSite.to_s,
inverse_of: :users,
autosave: true,
validate: false
include RailsAdmin::User
end
This is the solution we ended up going with which makes our files less nicely organized but doesn't require changes to application configuration.
Describe the bug I have a rails 6 application using mongodb. Currently if you edit any of our records in development mode none of editing infrastructure loads correctly. Boolean fields show as editable text, relationships just show id's, etc. This problem wasn't happening on our deployed servers and on further investigation setting eager_load to true everything loads correctly. We would like to be able to use rails admin on local development servers where we leave eager_load false. Is there a way to resolve this without setting eager load to true?
Reproduction steps Navigate rails admin create or edit for an object that relates to other objects in the database. Observe the fields. As an example User has the boolean field Test only:
User has many authorized sites:
User belongs to a primary authorized site:
Expected behavior In comparison if you set the configuration field eager_load to true the fields load correctly for editing:
we would like this functionality to work correctly without needing to set eager_load to true for development work. Is this a known issue or is something else going wrong?
Additional context
rails
version: 6.1.6.1rails_admin
version: rails admin 3.0.0mongoid
version: 7.5.1