+ All Categories
Home > Software > RBC Mod 1: Making a New Rails App

RBC Mod 1: Making a New Rails App

Date post: 18-Jul-2015
Category:
Upload: ameedahc
View: 40 times
Download: 0 times
Share this document with a friend
Popular Tags:
21
Making a New Rails App RailsBridgeChicago Module 1 Ameeda Chowdhury twitter.com/ameedahc
Transcript

Making a New Rails AppRailsBridgeChicago Module 1Ameeda Chowdhurytwitter.com/ameedahc

Create a new app by typing in the terminal command:$ rails new <appname>

Use the terminal to create and destroy files and directories for your app

Make a new app ‘railsbridgedogs’

These are the application files and directories created - see in terminal

Files generated for ‘railsbridgedogs’

App files & directories in text editor

Ruby Gems*Gems* are self-contained Ruby programs and libraries

When you make a new app it fetches *gems*.

These gems are specified in your app’s Gemfile.

You need to install the gems specified in your Gemfile.

bundle install Gemsbundle install will not work unless you’re in the app’s directory

Installing the Gems listed in Gemfile

bundle-install installs the dependencies specified in your Gemfile.

More bundle install Gems ...

bundle complete

What is Git?

How do we use Git?

What happens when we don’t use Git?Git is “version control” software that allows you:1. show the changes that were made to the code over time2. allows you to backtrack if necessary and undo those changes3. enables team collaboration on code

Why do we need Git?

Last, commit your files with a name in quotes “...”.These files, in their current state, will be accessible to you any time in the future by commit name, no matter whatchanges you make (in future commits).

First, initialize an empty git repository note the output

Then, add all your app’s files to the git repo

How do we use Git?

So… what is one object or thing you want users to be able to access for your dog adoption app?

Resource is any object you want users to be able to create, read, update, or delete by visiting its URL

Dog Resource!

A Rails scaffold quickly generates a complete set of files with basic codefor the named resource

The 4 most important scaffolded files for Dog1. Database migrations2. Model3. View4. Controller

Scaffold Dog Resource!

A database is needed to to store any dog records we create.We created a database on thelocal machine.

Migration files allow you to modify the database by adding or removingtables, columns, and entries.

In this case, the migration file produced by the Dog scaffold is run, and the Dog table is created.

Databases & Rails Migrations

Databases & Rails Migrations

...maps to the name attribute of instances of your Dog model.

$ rails console let’s you interact with your application from your terminal’scommand line.

The name database column of each row of your Dog table ...

The Dog model file will let you manipulate data stored in the dog database table.

The Dog model represents the data the logic of dog objects.

Rails Migrations -> Model!

The DogsController controller file processes the webserver’s requests and makes the Dog model’s data available to the views.

Controller --> Model data in Views

Run a local webserver to see your webpages run

visit http://localhost:3000/dogs

This is showing us the app/views/dogs/index page

This page is empty because we have not saved any dogs in our database.Create a few dogs with names!

Run Rails Server

Create a few dogs through this form.

The fields for the dog’s name in the new, edit, show, and index are there because we included ‘name:string’ in our scaffolding.

Creating through View Forms

@dogs is available in the view. each pulls out one dog instance at a time from inside your collection of all dogs @dogsapp/views/dogs/index

@dogs is an instance variable inside the index method storing the collection of all dogs pulled from the database app/controllers/dogs

Connecting Views to Controllers

<%= dog.name %> prints the dog’s name, once for each dog because it’s inside the loop app/views/dogs/index


Recommended