How to keep DRY with a ActiveAdmin or RailsAdmin, separate from the main application

戏子无情 提交于 2020-01-12 03:30:12

问题


I am building a JSON-only application, it is basically a leaner Rails, with fewer middleware and fewer modules. This is an application being built in Rails 4.

I want to to develop a simple app that can administrate the data in the database for the main-app. For this I would like to use Active Admin or Rails Admin. But both options somehow use the underlying models and their validations, requirements and such to build on top of.

This means that I need to share at least the models between the main application and the RailsAdmin application.

How would I best do this? Is there a good guide on how to build an administration-application in a separate rails app next to your main one, instead of having it integrated?

As a side note: another good reason to keep the admin in a separate application from the main app, but on a shared database, is the myriad of dependencies, a gem like ActiveAdmin comes with.

Also note that I am not simply interested in running admin on a different domain or different server, but mostly to keep main app lean and focused. And to keep the dependencies with which something like ActiveAdmin comes, out of my main app.


footnotes:

  • Neither ActiveAdmin nor RailsAdmin are problems for performance in themselves. It's that they require middleware, whereas a JSON-only Rail-app, needs only very few modules, helpers and middleware! Rails-API, offers such a slim stack. Performance is not about Admin vs. no admin, but Full-Rails vs Rails-API.
  • Performance is not my main problem, the dependencies and bloat is! I now have a Rails application that is so slim, focused and lean, that it can measure itself with most Sinatra apps :). With only three additional gems (each with a few dependencies of their own) and a very thin stack of middleware, I can upgrade, manage and debug very easily.

More practical: I don't have Devise (It's a JSON-API, so token-authenticated), don't have any views or template-engine. No Formtastic, No Paperclip, Rmagic, Kminari (pagers) and so on and so forth. All of which will be added to my app when I pull in "just an admin".


回答1:


This blog post describes an interesting approach: https://content.pivotal.io/blog/migrating-from-a-single-rails-app-to-a-suite-of-rails-engines

They use a nearly empty app as a container and mount their actual apps as Rails Engines.




回答2:


did you measure the impact of adding tools like ActiveAdmin to the speed of your rest API? if not, this sounds like a case of premature optimization to me.

in the case that the API speed really has an impact by a library that is loaded but not used, then you could create multiple applications and share the models in a git submodule.



来源:https://stackoverflow.com/questions/18133645/how-to-keep-dry-with-a-activeadmin-or-railsadmin-separate-from-the-main-applica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!