javascript manipulation of models?

Hi,   I need to know how to make a new model using user generated input about the name of the model and the schema. I'm fairly new to ror, so I don't even know if it's possible. My friend said you can do this using prototype and script.aculo.us ajax libraries but from the tutorials I've seen, none of them mention anything about being able to create models on the fly. If this is not possible with ajax, then please direct me towards the correct topic I should look into.

Thanks.

Hi,

Anything between back ticks (`) in Ruby will be run on the command line.

So say, your ajax posts to an action called create_model

def create_model   if params[:new_model]     `script/generate model #{params[:new_model}`   end end

That would create a new blank model file with the name passed to it as the parameter new_model. If the correct table exists, your model would work like normal.

When Rails creates a new model, it create a new migration file. If you also needed to create a new blank table for the new model.

`rake db:migrate`

Although, the table will be created, at this stage the table will have no fields. Adding fields to the model .. well that would probably require you to tap into

ActiveRecord::Migration.add_column(table_name, column_name, type)

Luke