Ruby on Rails basics
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
- Rails for Zombies: Interactive introduction to Rails (very basic - low-level)
- Ruby on Rails Tutorial - Learn Web Development with Rails: This (online) book by Michael Hartl is highly praised by beginners as well as experts.
- Gettings Started with Rails: First example app
- ActiveRecord guides: Guides for ActiveRecord (section "Models")
- apidock.com: Reference for Rails and Ruby
Find your way around an existing app
Let someone help you get the code for makandracards.com.
Have a look around. There will be much you don't understand, yet; 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? 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 the Ruby on Rails Tutorial.
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.
Write your own controller
Using a new or an existing app, create a model and a controller using Rails scaffolds.
Then rewrite it according to the pattern from the chapter "Beautiful Controllers" in our book Growing Rails Applications in Practice (it's in our library).
Which one do you like better? Why?
Movie database (MovieDB)
Write a rails app that lets you manage a list of movies, and a list of actors.
Movies can have multiple actors (and hence and actor starred in multiple movies).
- Keep the interface simple. For example, only allow the user to add a fixed number of actors to a movie at a time.