Ruby on Rails basics [4d]
Rails is our web framework.
- Be able to write a simple Rails application.
- Understand how Rails talks to the database (
- What is a model?
- How are records retrieved and saved?
- Gain an understanding of the structure of a basic Rails app
- Generate a controller using Rails scaffolding
- Write your own controller
- Learn how to do CRUD ("Create", "Read", "Update", "Destroy")
- How to show a list of existing database records
- How to build a user interface to show and update database records
- : This (online) book by Michael Hartl is highly praised by beginners as well as experts.
- : First example app
- : Guides for ActiveRecord (concentrate on the section "Models")
- : Reference for Rails and Ruby
Let someone help you get the code for makandracards.com.
Have a look around. There will be much you don't understand yetM AND THAT'S ok. don't lose yourself in the details.
Try to see if you can understand a few basic things in the code:
- What are the important models? For instance, what model represents a "card" like this one
- How are cards associated with our "makandra dev" deck at https://makandracards.com/makandra?
- Where is the form to update a card? The controller? The view?
- There is a feature to "repeat cards", that brings random "repeating cards" to the top of the deck, once a week. Search for "repeating", and see if you understand what's happening.
Work through theexcept for chapters 4.2 - 4.4, 9, 11 and 12.
For each chapter:
- You should do all the programming exercises.
- You can skip the testing exercises. There will be a later card to learn testing. We're also mostly using different testing frameworks and writing different types of tests than the tutorial.
- You can also skip the chapter "1.3 Version control with Git" and all deploying steps
Write a Rails app that manages a list of movies and a list of actors. We will call this app "MovieDB" in subsequent cards.
Movies can have multiple actors (and hence an actor can star in multiple movies). The user should be able to create a new movie/actor association from a movie's show view.
Your application layout should have a navigation bar to switch between sections (movies, actors).
We will use Rails 6 for our MovieDB. Create your new application like this:
gem install rails --version="~>6.0" rails new movie-db --skip-turbolinks
- Use alike
Castingto associate actors with the movies they star in. A movie's show view should link to associated actors. An actor's show view should link to associated movies.
- If you generate any code with scaffolding, you must understand every line of the generated code. Also delete any generated code that is not required for your application.
Refactor your MovieDB controlls to the pattern in our book(chapter "Beautiful Controllers").
The book is in our library.