0
0
Ruby on Railsframework~5 mins

Model generation in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of generating a model in Rails?
Generating a model in Rails creates a Ruby class that represents a table in the database. It helps manage data and business logic related to that table.
Click to reveal answer
beginner
Which command generates a new model named 'Article' with a 'title' string and 'body' text fields?
rails generate model Article title:string body:text
Click to reveal answer
intermediate
What files are created when you run the Rails model generation command?
Rails creates a model file (e.g., app/models/article.rb), a migration file to create the database table, and test files for the model.
Click to reveal answer
beginner
Why do you need to run 'rails db:migrate' after generating a model?
Because the migration file created by the model generator defines the database changes. Running 'rails db:migrate' applies those changes to the database.
Click to reveal answer
intermediate
How can you add validations to a Rails model after generation?
You add validation methods inside the model class, like validates :title, presence: true to ensure data meets rules before saving.
Click to reveal answer
What does the Rails model generation command create besides the model file?
AA migration file to create the database table
BA controller file
CA view template
DA stylesheet file
Which command applies the database changes after generating a model?
Arails db:migrate
Brails generate migration
Crails server
Drails console
How do you specify a string field named 'name' when generating a model?
Aname_text
Bstring:name
Cfield:name:string
Dname:string
Where is the model file located after generation?
Adb/migrate/
Bapp/controllers/
Capp/models/
Dapp/views/
What is the main role of a Rails model?
ARoute web requests
BManage data and business logic
CHandle user input forms
DDisplay data to users
Explain the steps and commands to create a new model in Rails and make it ready to use with the database.
Think about how Rails connects code to the database.
You got /5 concepts.
    Describe how you can add rules to a Rails model to check data before saving it.
    Consider how to keep data clean and correct.
    You got /3 concepts.