Creating migration through generator in ROR - ruby-on-rails

I am making an plugin in ROR and I want to make a migration file that will create a table. I am using generator for generating migration but not able to run it .
So please tell me the exact process to create a migration through generators.
Thanks!

http://izumi.plan99.net/manuals/creating_plugins-938a313a.html
go to this url

Related

Refinery CMS: generating migrations for existing models within an engine

I want to add an attribute to a model I've created within a Refinery CMS engine. I know I could do the following:
rails generate migration AddPartNumberToProducts part_number:string
Manually move the migration file from db/migrate to vendor/extensions/products/db/migrate
But is there a command to generate the migration into the correct folder in the first place?
Thanks!
The method I have outlined above is correct, according to #parndt (the lead developer of the Refinery project).

Is there a built in way to rename an entire scaffold?

I'm using Rails 3.2, and have started with a scaffolding and built out from it, but have realized I need to rename the entire scaffold (Model, View, Controller, db:migrate, etc). Is there a built in way to do this, or should I just do it manually?
I don't think there's anything rails provides to rename the name of models/controllers/views/tests etc. once they are created - whether as a part of a scaffold, or not.
You will have to change it manually.
If it is a brand new app that you have just started on, it might be easier to just delete the whole directory/drop the database, and start over again.
If not, you will have to go through the files created/modified by the scaffold generation, and modify them manually.
Make sure you either drop_and_recreate the relevant table, or add a migration to rename the table. See How do you write a migration to rename an ActiveRecord model and its table in Rails? for some relevant advice.
I think there's no out of the box method to rename files generated by scaffold.What you have to do is create a new scaffold and copy your codes from the old to the new.Copy contents from factories, model, controller and their respective spec file to the new scaffold. Then remove the old scaffold with the command
rspec d scaffold <Model Name>
and you have to create a new migration to drop that old table from the database. Then run your migrations.

Does the latest version of Rails require my db migration files to have "down" (undo) commands for the db?

Because it sure doesn't seem like it. When I generate a model and check out it's db migration file (I'm a bit of noob so forgive me for any ignorance), there is no "down" code which has been automatically generated. Is this because the newest rails versions have figured out how to handle this for me automatically?
The latest versions of rails support a method called change; if Rails can figure out how to reverse the migration simply by the contents of this migration--and it usually can if you use just the built-in migration methods--then you don't need to define a down method.
If you need to do something custom, or Rails can't figure out how to reverse the migration, you'll need to write up and down methods instead of change.

Adding a hook to script/generate migration

I do my Rails dev from xterm and in vim.
I'm getting sick of running script/generate migration do_whatever, then trawling through db/migrate trying to tab-complete to 20091015235018_do_whatever when there's 5 other migrations with similar timestamps.
What's the best way to add a hook to open the generated migration in vim?
I'd rather not hack into Rails' core in /usr/lib as I work from several systems and can see myself wanting to create numerous such hooks. However, it doesn't really seem plugin worthy.
There are lots of simple ways to get the name of the generated file, but I'm not sure how to cleanly hook it into the generation. What do you think?
A better option with vim is to use rails.vim and type :Rmigration do<TAB>
It ignores the timestamp ...
You can also create and edit a migration in one go by typing :Rgenerate migration ...
I just submitted a patch to Rails to add an --editor option for just this case, which you could backport into whatever version of Rails you're using now. If you don't specify which editor you want it tries to use EDITOR

Getting tables to work is RadRails?

When I manually enter tables into the .rb file in the migrate folder nothing shows up. I have followed a few different "how to's" but I can't get the tables to show up when I preview my work. I can however get one table to show up if I create it in the parameters when generating a scaffold, but that's one table. I have Rails version 2.3.4 and version 1.2.3 installed on my lame Windows Vista. I have tried using both versions multiple times. I am also trying to follow the Ruby on Rails for Dummies book, but it seems a little outdated. Any tips on getting tables to work? Its supposed to be really simple and take "just minutes" to complete this simple app. Maybe something didn't install right? Maybe a better book?
Just want to make sure you're using all the tools available to you:
To generate a migration file:
./script/generate MigrationFileName
Take a look at the Database Migrations Guide from the official Rails Guides for the correct syntax and options for creating a migration file.
Once you've created your migration, you need to run the following:
rake db:migrate
This will populate the database with the information specified in the migration file.

Resources