• Up and down methods: in Ruby

    These methods are called when a migration is applied and rolled back respectively. The numbers 001 in the file name is the serial number of the migration, it is used to determine the order in which migrations are applied, while rails store its version in the database so as not to apply one migration several times. To migrate a database to a specific version, run db:migrate with the VERSION parameter:

     

    <code>$>rake db:migrate VERSION=0</code>

     

    As a result, the database migrates to the zero version, when no tables have yet been created using Ruby on Rails. This is a convenient way to clean up the database after experimenting with the application. Then you can call db:migrate again without parameters, as a result all migrations will be applied.

     

    The directory is great, but the articles are not formatted.

     

    I hope you have already looked at the catalog and made sure of this. Time to tackle the main task of the application - the formatting of articles.

     

    We already have the code for formatting, now we need to understand how to use it. In the first version, we only had a controller, so the code was located directly in it, now there is an Article model, but if we place the code in a model, we will hard-wire the formatting to a specific model, and this will lead to the fact that we cannot reuse the code , although it does not depend on the model that it will format.


    Tags Tags : , ,