Midterm Qs : Rails MVC Flashcards
Know about MVC architecture and what it aims to do.
-consists of three main types of code: Models, Views, and Controllers
-every user action that can be performed on a web page—clicking a link or button, submitting a fill-in form, or using drag-and-drop—is eventually handled by some controller action, which will consult the model(s) as needed to obtain information and generate a view in response.
-is one of a family of patterns for structuring interactive applications.
-distinguishes models that implement business logic, views that present information to the user and allow the user to interact with the app, and controllers that mediate the interaction between views and models.
What is a model?
-the main data managed by the app
-stored in a relational database using the Active Record design pattern
What is a view?
-allow users to see and interact with the data
-serve as the interface between the system’s users and its data
-use the Template View pattern to create HTML and JSON representations of the app’s models.
What is a controller?
-mediate interaction between the views and models
-follow REST in which each controller action describes a single self-contained operation on one of the app’s resources
The (a) blank subsystem is responsible for mapping incoming HTTP requests to (b) and extracting any required or optional parameters.
(a)Routing Routes
(b)Controller actions
Which type of variables are accessible to views?
instance variables
What does a scaffold do?
easily creates a model view and controller for quick development
Know where to find models, views, and controllers in the Rails directory structure.
app/models/model.rb
app/views/models/action.rb
app/controllers/model_controller.rb
Know which file to find the routes in a Rails project.
config/routes.rb
If you generate scaffold for a resource Movie, what is the name of the controller and which file is it located at?
app/controllers/movies_controller.rb
If you generate a scaffold for a resource Movie, what is the name of the model and which file is it located at?
movies.rb
If you generate a scaffold for a resource Movie, what is the name of the database table created?
Movies
What is ActiveRecord and what power does it give Rails models?
-(ActiveRecord)refers to the code module that instantiates the pattern in the Rails framework
-(Active Record)allows Rails models to know how to C,R,U,D themselves in the database without the developer knowing the required SQL commands to do it.
-uses convention over configuration to infer database table names from the names of model classes and to infer the names and types of the columns(attributes) associated with a given kind of model.
-can query and filter.
-The power for Rails models is that it becomes resources whose instances are stored in a relational database.
Where does Rails keep the description of the structure of your database?
Active Record