views:

86

answers:

3

I still learning Ruby on Rails, but have been wondering what happens if I make a mistake. For example, if I scaffold and make a typo, what do I do? If I don't do scaffolding, generate a model, rake db:migrate it and find out I need to ad a column or delete one, what do I do? Is it better sometimes to use a third party manager on the database instead of letting RoR do it all? I'm not sure how to feel about designing with RoR. I can't be perfect with it every time!

Thanks

+6  A: 

There's typically a way to fix any issues in rails as long as you know how to do it. you can create new migrations to fix old ones, or rollback the database and change the original migration. All of the rails generate functions also have destroy functions as well. If you mess up a scaffold and catch it right away, just destroy it and do it again. For example, in rails 3:

rails generate model ModelName

can be reversed with

rails destroy model ModelName

in rails < 3 the syntax is ruby script/generate and ruby script/destroy respectively. Google how to reverse migrations. Let rails do the hard work for you, no point in reinventing the wheel with a third party app.

As for version control, LEARN IT. I had no idea how to use git when I started and it's saved my butt more times than I can count. Setup an account with github, it makes learning git SUPER easy.

When you get stuck, trust stackoverflow. People here are really helpful and never judgmental. Great resource for beginners and pros alike!

Ryan
haha, didn't see your reputation score. Guess you already know how awesome stackoverflow is ;-)
Ryan
A: 

Use source control. If you make a mistake, simply revert the changes and any generated files disappear.

In migrations, if you make a mistake in your development environment, simply drop the database, edit the incorrect files and migrate the database again. You only really need to worry about migration integrity once they go into production or are shared with another party.

Toby Hede
A: 

I would suggest git for local source control. Especially Generators do a lot of work, you should use a safeline. git gives you that without too much hassle - and you don't need a server.

  • git init - will generate the local repository in .git
  • git commit -a -m"message" - commits the changes
  • git reset (--hard) master - gives you back the last commit

There are good introductions on github.com and on http://gitready.com.

Lukas Eppler