Giter Site home page Giter Site logo

stublag / ruby-on-rails-exercises Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pcantrell/ruby-on-rails-exercises

0.0 1.0 0.0 140 KB

Home Page: http://smartfactory.com/courses/ruby-on-rails

License: MIT License

Ruby 92.36% JavaScript 4.19% CSS 3.45%

ruby-on-rails-exercises's Introduction

Smart Factory Ruby on Rails exercises

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.

Development Setup

Fork the project

Use the 'Fork' button on the upper right of the project's github page.

Later on, to update your fork, you'll need to do two things:

$ git remote add upstream [email protected]:gosmartfactory/ruby-on-rails-exercises.git
$ git fetch upstream

Only the second command will be required for future updates. Now, if you want to see what new branches are available to check out and merge from,

$ git branch -r 

Check out a local copy:

$ git clone [email protected]:<your_github_username>/ruby-on-rails-exercises.git

Install the dependencies

$ cd ruby-on-rails-exercises
$ bundle install

Exercise Set #1

Add a gem

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

Generate a scaffold

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.

Migrate the DB

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.

Improve the style

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.)

Allow blank 'paid' dates to be entered

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.

Add validation rules

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.

ruby-on-rails-exercises's People

Contributors

jslag avatar pcantrell avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.