# Javascript manipulation of models?

**URL:** <https://www.ruby-forum.com/t/javascript-manipulation-of-models/140950>\
**Category:** Rails\
**Created:** [June 20, 2008, 1:04am UTC](https://www.ruby-forum.com/t/javascript-manipulation-of-models/140950 "2008-06-20T01:04:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vshyam121](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/85e7bf/32.png) [@vshyam121](https://www.ruby-forum.com/u/vshyam121)\
**Post date:** [June 20, 2008, 1:04am UTC](https://www.ruby-forum.com/t/javascript-manipulation-of-models/140950/1 "2008-06-20T01:04:10Z")

</div>

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](http://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.

---

<div class="post-metadata">

**Author:** ![vshyam121](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/85e7bf/32.png) [@vshyam121](https://www.ruby-forum.com/u/vshyam121)\
**Post date:** [June 20, 2008, 5:05am UTC](https://www.ruby-forum.com/t/javascript-manipulation-of-models/140950/2 "2008-06-20T05:05:44Z")

</div>

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

On Jun 20, 11:04 am, Shyam Vijayakumar \<rails-mailing-l…@andreas-
