Rails Tutorial : Beer shop Part I – Scaffolding
by toy
I have decided to jump to rails, because I have seen how fast to build an application and how easy it is. I have been a Java Programmer quite a long time, and played with Grails and Rails as well. So, I decided to create this tutorial for my benefit to practice my rails techniques. It is an very simple beer shop. I will start from scratch.
Prerequisite.
1. Netbeans (I use Netbeans because it provides the rails plugin and everything with one click.
2. MySQL
That’s it. Let’s start
3. Configure database: you have to put your own attributes; username and password that correspond with your database configure, don’t worry you can change it later at file database.yml

4. Click Finish
So now, you should have your first rails application created. Try and run it you will get this page. If you don’t get this page, you might have to check with your database configuration. If you are developing non-database application you might have to turn off the database connection.

Next, we are creating a scaffolding, this magic command will create everything for us, CRUD and a simple page
5. Right click on your project and choose generate

6.
Model Name:
1 | beer |
Attributes Pairs (field:type) :
1 | name:string abv:string bottle_size:decimal case_size:decimal price:decimal |
Oh, ahh and don’t for get to create a database in MySQL as well
1 | CREATE DATABASE BeerShop_development |
Now we have got a schema already, we just have to migrate those to our database, by using db:migrate command or run
1 | rake db:migrate |
You will now have a beer already. try to run http://localhost:3000/beer on your browser. We will have CRUD beer ready to use. It’s a very ugly page. We will jazz with it later.
I’m gonna continue this next week.





Twitter
Facebook
Pingback: Programming Blog » Blog Archive » Rails Tutorial : Add testing data by using migration