How can I create a dynamic domain class in Grails - grails

How can I create a dynamic domain class in Grails.
Let's say I want to create a new domain class whose class name and properties is known in the run-time. How to create it and persist it in Grails?
Many thanks,

There's a plugin for that: http://www.grails.org/plugin/dynamic-domain-class

the plugin seems to be abandoned, and in the google group of the project the deveoper say that there is some important issue and he said we can't using it in production, and there is no evolution since 2011, I hope that the founder of the idea Burt Beckwith can help us to continue this plugin, because it is really an interesting thing, there is too much possiblity behind the scene.

I'm working to get this to work on grails 2.4.4, I'm very close at getting it to work, only need to make a new instance of sessionfactory to work :)

Related

What is a good way to store global site settings in Rails that are editable by an admin?

I'm working on a rails portfolio application which only has an admin(s) to manage the site. The admin should for example be able to change the site name or the header image. What is a good way to implement this?
I personally like to use the singleton pattern in that case. It's basically a class that you have only one instance. So we could call it SystemSetting, for example, and add the attributes for the settings as as you like. I believe this article could give you some direction about singleton in ruby: http://dalibornasevic.com/posts/9-ruby-singleton-pattern-again. Good luck!

Adding properties to users

I would like to know how I can add more properties to users in my website.
I am using the default user template that is made with a MVC project.
I tried using the answer to
this post, but I keep getting:
The model backing the 'ApplicationDbContext' context has changed since the database was created
I believe I am missing something that isn't written in that post, can anyone point me to what I need to do?
Thanks.
You have to migrate and update your DB after changing default User model in Identity. Try with that.
I have figured out the answer.
The default user identity model comes with it's own context.
Everywhere I looked, people were always creating an additional context and I thought they both worked together just fine.
Apparently You need to work with each one separately(add migrations to each, and update database with each).

Do I need to implement the CRUD Methods in grails?

I am using scaffolding in my application. However, I was wondering if I now really need to implement the CRUD Methods in my Controller class for example concerning production mode.
btw I am using grails 2.3.4
I appreciate your answer!
This is a rather odd question. You don't need to do much at all - make your app the way you want. If the generated CRUD pages help you, use them, otherwise don't. You can use them as starter code, removing actions and other code that you don't need and adding new code as needed. You can create code by hand or via scripts. Do what works for you :)

Modifying a domain class after objects have already been persisted with that class

This question is similar to the question here.
Let us assume that I have made a Grails application and then, sometime down the road, I need to add a field to a domain class. What would be the best way to add that field and have all the objects already persisted to the database be updated too? Is there anyway to do this in Grails (currently using 1.3.7, but upgrading to 2.0 when it is stable) without manually accessing the database?
Use this plugin: http://grails.org/plugin/database-migration

How to ad users using A shiro Plugin

I am using Shiro plugin for my grails application security, My application already has a user .Using the shiro plugin, we get a shiro user, now how do i integrate the shiro user with the normal user of my application,show i go ahead and use relationships or is it that the user class ahould be only a shiro user class now ??
The Grails Shiro Plugin auto-generates the ShiroUser class as a starting point that you can use directly, or, if you don't want to use it, an example that helps you configure your own data model to work similarly. It is totally ok to use your own classes instead.
And in my opinion, it is a good thing to use your own classes: there are less classes to maintain and you have Shiro work with your existing data model rather than forcing you to use new classes and/or interfaces. The Grails plugin creates these things as a convenience to reduce the time it takes for you to get up and running, but you don't need to use them if you don't want to.
Using the ShiroUser class (and even further, using the Nimble plugin, which is built on top of Shiro) is all about convenience - how much do you prefer to use something that already exists (with the caveat that it may not meet all of your needs) vs how quickly do you want to get up and running.
Cheers,
Les
Apache Shiro PMC Chair & Katasoft Inc. Founder:
Application Security Products & Professional Apache Shiro Support and Training:
http://www.katasoft.com
Check out the nimble plugin which does exactly this and more:
http://www.grails.org/plugin/nimble

Resources