Rails migration:
Rails migration enables you to do the following.
-->If one person makes a change all the other person needs to do is to just update it and run in a team of developers.
-->When working with multiple systems migrations help in synchronization.
Rails migrations does the following things,
-->create table,drop table ,rename table
-->Add column,delete column,change column ,rename column
-->Add index and remove index extra.
They also support all the basic data types.
--> Convenient way to alter your database in a structured and an organised manner.
-->For
each an every alteration you do to a database,in terms of creation and
updation it stores as an unique migration in db/migrate.
-->The
name of the migration is based on the timestamp ending with the class
name.If you want to change the class name chamge the name of the model
else you will get an error saying "No class found".You can also rollback
databases whenever you want to undo any new changes that you have
created.
Creating the migrations:
It will be done directly on scaffolding.Other way to create is
ruby script/generate migration table_name
You should use lower case for the table-name that is the rails paradigm.This will create a file in the db/migrate directory which has the structure of the table necessary.
Running the migration:
run db:migrate
As we create migrations we should also write code to rollback to its
Scaffolding:
-->Enables us to find how the rails exactly works.
-->Quick code to demonstrate and get feedback on rails.
If you are using scaffolding to create a rails application all your work will become very easier.
If you dont use scaffolding you have to create the project,its model,its view and controller,the routing paths,the database ,you have to populate them etc.In using scaffolding all are automatically created .
All the CRUD functions,Create,Delete,Update and Retrieve functions are directly inserted into the controller and doesnt need to be manually added.
Configuring database.yml file :
This is a very sensitive file.This displays the 3 different environment it offers and the various databases it uses along with the settings and the details.The username and the password for each of the db is also mentioned here.The spaces in this should be given carefully .Any extra space or error will not let you run the create db cmd like
rake db:create
The above will give an error "Rake aborted"
The console:
This can be accessed using the rails.console command.
The rails server is run using the "rails.server "command.
Configuring :
The config folder has all the configuration settings of the project.The routs file in that is used to specify where the control is to be redirectd.
What are helpers??
They are used when you have to do some small logic computation relating to the view.For example to get the full name of an user by the concatenating operator.The concatenation is done with the help of a helper.Only the view can access the helper methods.The helper methods are put in a module.The model functions can be accessed using the helpers but not directly.The objects are passed as arguments to the helper by the views,so that the helper can access it.
Simple start with Rails:
After knowing the few of the above basics i started creating a simple rails application using the below link
http://guides.rubyonrails.org/getting_started.html
No comments:
Post a Comment