0% found this document useful (0 votes)
21 views

Rails 4 Diff

The document summarizes some of the key changes in Rails 4 including strong parameters for mass assignment, concern routing, declarative ETags, live streaming, ActiveModel::Model, PostgreSQL arrays, Turbolinks updates, and testing changes.

Uploaded by

Daniel Olivares
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Rails 4 Diff

The document summarizes some of the key changes in Rails 4 including strong parameters for mass assignment, concern routing, declarative ETags, live streaming, ActiveModel::Model, PostgreSQL arrays, Turbolinks updates, and testing changes.

Uploaded by

Daniel Olivares
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

OWNING

The Rails 4 Diff Cheatsheet

RAILS
MASTERCLASS

by owningrails.com

Strong Parameters

CONTROLLERS

Routing
concern :commentable do
resources :comments
end

params.require(:post).
permit(:title, :body)
Includes routes inside concern

resources :messages, concerns: :commentable

Declarative ETags
class InvoicesController < ApplicationController
etag { current_user.try :id }

Live Streaming

def show
@invoice = Invoice.find(params[:id])
fresh_when @invoice
end
end

class MyController < ActionController::Base


include ActionController::Live
def stream
response.stream.write "data"
response.stream.close
end
end

Tests
test/units
test/units/helpers
test/functional
test/functional
test/integration

MODELS

Migrations
reversible do |dir|
change_table :products do |t|
dir.up
{ t.change :price, :string }
dir.down { t.change :price, :integer }
end
end

class Person
include ActiveModel::Model
attr_accessor :name
Adds validation & allow to
end
use in controllers & views.

PostgreSQL only

person = Person.new(name: 'bob')

Query

Scopes

Ticket.all
Ticket.my_scope.load
Ticket.my_scope.to_a
Ticket.none

VIEWS

ActiveModel::Model

revert SomePreviousMigration
t.integer :int_array,
array: true
t.string :string_array, array: true

test/models
test/helpers
test/controllers
test/mailers
test/acceptance

Doesnt load records. Returns a relation.


Load records. Returns a relation.
Load records. Returns Array of records.

Returns an null relation. Always returns no records.

class Ticket < ActiveRecord::Base


default_scope { ... }
scope :opened, -> status { ... }
end

Turbolinks
<link ... type="text/css" data-turbolinks-track>
<script ...
data-turbolinks-eval=false>
<a ...
data-no-turbolink>

Track asset for changes


Do not re-eval when restored from cache
Load URL w/o Turbolinks

Tired of trying to keep up with the latest changes in Rails? Join the Owning Rails Masterclass and master Rails once and for all!

owningrails.com

Coded Inc.

You might also like