This set of exercises will lead you through building an app that allows a bicycle shop's employees to track orders for fulfilling custom bicycle orders.
Use the 'Fork' button on the upper right of the project's github page.
$ git clone [email protected]:<your_github_username>/ruby-on-rails-exercises.git
$ cd ruby-on-rails-exercises
$ bundle install
Before writing any code, we would like to make a configuration change. Most projects we see use the Haml templating language, rather than Rails' default ERB. So, let's configure the app to use Haml.
Add the following line to Gemfile
:
gem 'haml-rails'
Now type rails s
to start the server. You'll get an error, because the gem you just added isn't installed yet. Tell bundler to install the missing gems:
$ bundle install
Our initial requirements are simply to allow creating and listing orders with a few fields for each order:
customer_name
customer_email
description
price
paid_for_on
(the date that the bike was paid for).
Since this sounds like standard CRUD, use rails' scaffold generator to create an Order
model and UI. You used the scaffold generator already if you followed the pre-class install instructions. For a review of how it works, run
$ rails g scaffold
from the command line of your project directory.
Now that the generator has defined a table, it's time to set up the database:
$ rake db:migrate
If your server isn't already running, start it:
$ rails s
Point your web browser to http://localhost:3000/orders
, and create a few orders.
They're pretty hard to read in the listing, aren't they? We've put some simple CSS together that should help with that, and stuck it in examples/orders.css.scss
. Put those rules in an appropriate place so that Rails knows about them, then modify the orders index view so that the new CSS rules get used.
(No worries if you aren't familiar with CSS! Just ask and we'll give you a few hints about what you need to do.)
The default UI for entering the date that the order was paid for doesn't allow the field to be left blank, which is necessary in case the customer hasn't paid yet. Change it to a text input, so that it can be left blank until the order is paid for.
As the app stands now, it's possible to create orders that are missing vital information. Let's fix that -- make the customer name, customer email, description, and price required.