Rails Fundamentals Session One

Rails Fundamentals Session One

This class

Get started

Generate a rails application

rails new

Start a new rails server

rails s

Generate Controllers

rails g controller

Routes (Verb + URL)

Inspect the logs

To see additional options that are offered by the rails cli

rails -h

Rails has smart defaults and it will reload everything for you in the development environment.

Mockup HTML with Bootstrap



Working with Data - active models and rails console!

Generate the model

rails g model

It’s better to generate the resource, which includes the RESTful routes

rails g resource

Active Record migration

Instance variables

@questions = Questions.all

This is a rails convention, all the instance variables are available in the view.

View Helpers

Built-in helper


Create Action

  1. Add a Button
  2. Pass the params
  3. In the create method in the controller

Strong parameters

Use secure parameters

def secure_params
  params.require(:question).permit(:email, :body)

Next class

Referencing URLs with names and helpers


Subsequent classes