This is the sample application for Ruby on Rails Tutorial: Learn Web Development with Rails by Michael Hartl.
All source code in the Ruby on Rails Tutorial is available jointly under the MIT License and the Beerware License. See LICENSE.md for details.
To get started with the app, clone the repo and then install the needed gems:
$ bundle install --without production
Next, migrate the database:
$ rails db:migrate
Finally, run the test suite to verify that everything is working correctly:
$ rails test
If the test suite passes, you'll be ready to run the app in a local server:
$ rails server
For more information, see the Ruby on Rails Tutorial book.
- There is a command to generate controllers:
$ rails generate controller ControllerName <optional action names>
-
New Routes are defined in /config/routes.rb
-
Rails views can contain static HTML and/or ERb (Embedded Ruby).
-
Testing can drive development of new features, allow for refactoring, and catch regressions.
-
Rails Layouts allow a common template for pages in our application to make things DRY.
- Strings are probably the most important data type in web development.
-
HTML5 has header and footer tags.
-
Bootstrap framework allows quick design of a nice looking site.
-
Sass/Less offer improvements upon CSS.
-
Integration tests simulate a browser clicking from page to page.
-
Common validations include presence, length, and format.
-
Defining a database index is like a book index. It also helps lookup efficiency and can enforce uniqueness at the database level.
-
We can add a secure password to a model using the built-in 'has_secure_password' method.
-
The debug method displays useful debugging information.
-
SASS mixins are like Ruby modules.
-
Data should be treated as a 'resource' in the REST API mindset.
-
Gravatars are a convenient way of displaying avatars to represent users.
-
Integration tests can also check form submission behavior and catch regressions.
-
We can configure our production application to use SSL for secure communications (by uncommenting a line in config/environments/production) and use Puma for high performance.
-
TDD is useful when debugging by reproducing the bug in a test.
-
Sessions can persist state.
-
We can change features such as links on the layouts based on login status.
-
Integration tests can verify correct routes, database updates, and proper changes to the layout.
-
Rolling your own authorization system is very confusing.
-
Rails can maintain state using persistent cookies.
-
Remember Tokens and Remember Digests are the tools to maintain a persistent session.
-
Login status is determined by the presence of a current user based on the session's user ID or the permanent session's unioque remember token.
-
The application signs users out by deleting the session's user ID and removing the permanent cookie.
-
Authorization is implemented using before filters.
-
Authorization tests use both low-level commands to submit HTTP requests to controller actions and high-level integration tests.
-
'Friendly forwarding' redirects users where they wanted to go after logging in.
-
Pagination shows a bunch of stuff split into multiple pages.
-
db/seeds.rb lets you 'seed' the database with sample data.
-
'render @users' automatically calls the _user.html.erb partial on each user.
-
A boolean attribute in the database automatically creates a #attribute? boolean method on the Model's objects.
-
Fixtures can produce a large amount of test data using embedded Ruby.
-
Account Activations can be modeled as a resource, even without an Active Record object.
-
Rails can generate Action Mailer actions and views to send email.
-
Instance variables defined in mailer actions are available in mailer views.
-
Account activations used a generated token to create a unique URL for activating users and a hashed activation digest to securely identify valid activation requests.
-
Both mailer/integration tests are useful for verifying User mailer behavior.
-
SendGrid is a heroku emailer.
- Password Resets can be modeled as a resource and used similarly to sessions and account activations.
-
Rails supports multi-key indices.
-
Scopes take anonymous functions as arguments using the stabby lambda syntax.
-
Fixtures support associations.
-
CarrierWave is a useful gem for uploading and resizing images.
N/A