1

Im new to both ruby and rails, but have experience with java, javascript and a little python.

I am thinking of creating a web application where it should be possible to create different things (models) with various properties and connections (relationships) between them. Ruby on Rails seems to have support for some schemaless backends (mongodb, neo4j etc) so it has caught my interest. Is it possible to build a web interface for creating new RoR models, adding properties and relationships to them? I want the user actions in the web interface to translate to new models with the specified properties on the RoR server. And these models should of course be persisted in some way (could they be persisted as ruby files perhaps?). I guess you could see it as a CMS in some ways.

What are the tools or concepts I should be googling for?

regards Oskar

oskbor
  • 1,592
  • 18
  • 35
  • 3
    Keep in mind "possible" and "good idea" are two different things. – tadman Jun 26 '12 at 18:12
  • 1
    You can do it (http://stackoverflow.com/a/10724280/479863) but I think you should rethink your data model first. There certainly are cases where you'd want users to create new tables on the fly but you should think twice (at least) before building a platform within a platform. – mu is too short Jun 26 '12 at 18:46

1 Answers1

2

It's certainly possible to do what you ask and there are several different approaches but I would suggest that you look deeper at your requirements.

In languages other than Ruby I've helped others architect & build similar meta-modeling CMS frameworks. The first one was done in 1999: full Web GUI for creating models and relationships between them straight from the browser. The reason why we had to do this back then was that the underlying platforms we were using made it rather difficult to create models and do MVC so we had to help developers with both framework code & GUI tools.

Ruby as a language is well-suited for internal domain specific languages. Rails uses internal DSLs a lot, especially in ActiveModel. Because of this, it is often far easier to write the basic code for a Rails model then it is to use some other (higher) level of abstraction. GUI tools, in particular, are very tough to deal with when it comes to building good models because of roundtripping: the need to be able to allow for code to be changed by hand and that change to be reflected in the GUI. It's a tough problem.

With all that said, if you still want to go with a GUI-based meta-modeling approach, there are two main paths you can choose from:

  1. Building parameterized RoR meta-models
  2. Generating specific RoR models

From the phrasing of your question it seems you are interested in (2). In that case, there are two standard approaches for going about this: you either interpret or compile. If you interpret then you create a DSL for describing models and its execution instantiates the models in the Rails environment. (In Ruby classes are defined by executing code that defines them so this is all perfectly normal.) If you compile than you'll code-generate standard RoR models that use your favorite persistence framework. The question then becomes where will you keep the code. You can write it to disk and load it. You can also store it in a database, for example. In both cases you may want to look at gems such as sourcify.

On a side note, if you choose to build this type of system, I'd highly recommend you go with a NoSql document-oriented persistence mechanism, e.g., MongoDB using something like Mongoid. The reason is that Rails provides limited support for SQL schema management and even less workflow automation (beyond basic migrations). Give people a GUI and they are likely to mess with schema more frequently. Therefore, you'll have to deal with the schema migration problem. Document databases make this a little simpler (partly by punting on the problem at leaving it to code to deal with issues in a lazy manner). Relational databases usually don't let you do that. They require up-front schema migration effort and that will add lots of requirements to your system and friction to the overall developer workflow.

Good luck!

Sim
  • 13,147
  • 9
  • 66
  • 95