Professional Documents
Culture Documents
Basic Database
Basic Database
Basic Database
cd library
script/server
Apart from creating many other files and directories, this will create files named
book.rb and subject.rb containing a skeleton definition in app/models directory.
Now you need to tell Rails what relationships you want to establish within the library
data system. Modify book.rb and subject.rb according to association required.
Create Migration
This will create the file db/migrate/001_table_name.rb. A migration file contains basic
Ruby syntax that describes the data structure of a database table.
It will define the probable structure that we require in our database table, in file created
in db/migrate which was created at the time of creating model. Second way, We can do this
directly by adding structure in those model files.
Now you have created all the required migration files, its time to execute them against
the database.
Run the Migration
rake db:migrate
set RAILS_ENV=development
rake db:migrate
If you would like to specify what rails environment to use for the migration, use the
RAILS_ENV shell variable.
Now we have our Database and required Tables available. In the two subsequent
chapters we will explore two important components called Controller (ActionController) and
View (ActionView).
We will create just one controller here. This command accomplishes several tasks, of
which the following are relevant here
Rails lets you know that you need to create the view file for the new method. Each
method you define in the controller needs to have a corresponding .html.erb file, with the same
name as the method, to display the data that the method is collecting.