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

Partials

Actions

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

form_for

Create Action

  1. Add a Button
  2. Pass the params
  3. In the create method in the controller
    Question.create(params[:question])
    

Strong parameters

Use secure parameters

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

Next class

Referencing URLs with names and helpers

Relationships

Subsequent classes