SlideShare a Scribd company logo
Rails 4.0
Nikola Šantić
• MVC Web Framework
• Verzija 1.0 - prosinac 2005.
• “Convention over configuration”, DRY
• Najbolji je
• 235.000 siteova
Ruby on Rails
• MVC Web Framework
• Verzija 1.0 - prosinac 2005.
• “Convention over configuration”, DRY
• Najbolji je
• 235.000 siteova
Ruby on Rails
• MVC Web Framework
• Verzija 1.0 - prosinac 2005.
• “Convention over configuration”, DRY
• Najbolji je
• 235.000 siteova
Ruby on Rails
• MVC Web Framework
• Verzija 1.0 - prosinac 2005.
• “Convention over configuration”, DRY
• Najbolji je
• 235.000 siteova
Ruby on Rails
• MVC Web Framework
• Verzija 1.0 - prosinac 2005.
• “Convention over configuration”, DRY
• Najbolji je
• 235.000 siteova
Ruby on Rails
Promjene
Promjene
verzije commits files changed lines changed
1.2 - 2.0 1,989 1,106
61,774 +
38,554 -
2.3 - 3.0 10,000+ 2,334
131,438 +
106,109 -
3.0 - 3.1 6,818 1,522
74,115 +
62,646 -
3.2 - 4.0? 7,304 2,005
94,231 +
92,069 -
Pretpremijera
# Gemfile
# gem 'rails', '3.2.8'
gem 'rails', github: 'rails/rails'
$ bundle update
NOVE
STVARI
Strong Parameters
# app/models/user.rb
class User < ActiveRecord::Base
end
# app/controllers/users_controller.rb
class UsersController < ApplicationController
def update
# params = {user: {name: 'Nikola', age: 25}}
@user = User.find(params[:id])
@user = @user.update_attributes(params[:user])
redirect_to @user
end
end
Mass assignment
# app/models/user.rb
class User < ActiveRecord::Base
end
# app/controllers/users_controller.rb
class UsersController < ApplicationController
def update
# params = {user: {name: 'Nikola', admin: true}}
@user = User.find(params[:id])
@user = @user.update_attributes(params[:user])
redirect_to @user
end
end
Mass assignment
# app/models/user.rb
class User < ActiveRecord::Base
end
# app/controllers/users_controller.rb
class UsersController < ApplicationController
def update
# params = {user: {name: 'Nikola', admin: true}}
@user = User.find(params[:id])
@user = @user.update_attributes(params[:user])
redirect_to @user
end
end
# @user.admin?
# => true
Mass assignment
# app/models/user.rb
class User < ActiveRecord::Base
attr_accessible :name
end
# app/controllers/users_controller.rb
class UsersController < ApplicationController
def update
# params = {user: {name: 'Nikola', admin: true}}
@user = User.find(params[:id])
@user = @user.update_attributes(params[:user])
redirect_to @user
end
end
# @user.admin?
# => false
Mass assignment
config.active_record.whitelist_attributes = false
# app/models/user.rb
class User < ActiveRecord::Base
end
# app/controllers/users_controller.rb
class UsersController < ApplicationController
def update
# params = {user: {name: 'Nikola', admin: true}}
@user = User.find(params[:id])
@user = @user.update_attributes(user_params)
redirect_to @user
end
private
def user_params
params.require(:user).permit(:name)
end
end
Strong parameters
params.require(:user).permit(:name, :email, :password)
Strong parameters
params.require(:user).permit(:name, :email, :password)
Strong parameters
POST /users
params = {username: ‘Budala’}
params.require(:user).permit(:name, :email, :password)
Strong parameters
POST /users
params = {username: ‘Budala’}
<= 400 Bad Request
params.require(:user).permit(:name, :email, :password)
Strong parameters
POST /users
params = {user: {name: ‘Nikola’, admin: true}}
params.require(:user).permit(:name, :email, :password)
Strong parameters
POST /users
params = {user: {name: ‘Nikola’, admin: true}}
<= 201 CREATED
User.find_by_name(‘Nikola’).admin?
=> false
# app/controllers/users_controller.rb
class UsersController < ApplicationController
def user_params
params.require(:user).permit(:name)
end
end
# app/controllers/admin/users_controller.rb
class Admin::UsersController < ApplicationController
def user_params
params.require(:user).permit(User.attribute_names)
end
end
Višestruke uloge
https://github.com/rails/strong_parameters
Dostupan već danas!
ActiveSupport::Queue
• delayed_job
• Resque
• Sidekiq
• ...
Background job - Prije
class ExpensiveOperation
def run
# ...
end
end
Rails.queue.push(ExpensiveOperation.new)
Background job - Sada
config.queue = :asynchronous
config.queue = :synchronous
config.queue = :resque
Podešavanje
config.action_mailer.async = true
Asinkroni ActionMailer
ActionController::Live
class MyController < ActionController::Base
def index
100.times {
response.stream.write "hello worldn"
}
response.stream.close
end
end
Streaming
class MyController < ActionController::Base
include ActionController::Live
def index
100.times {
response.stream.write "hello worldn"
}
response.stream.close
end
end
Streaming
class MyController < ActionController::Base
include ActionController::Live
def index
100.times {
response.stream.write "hello worldn"
}
response.stream.close
end
end
Streaming
WEBrick
class MyController < ActionController::Base
include ActionController::Live
def index
100.times {
response.stream.write "hello worldn"
}
response.stream.close
end
end
Streaming
WEBrick
class MyController < ActionController::Base
include ActionController::Live
def index
100.times {
response.stream.write "hello worldn"
}
response.stream.close
end
end
Streaming
WEBrick Unicorn
class MyController < ActionController::Base
include ActionController::Live
def index
100.times {
response.stream.write "hello worldn"
}
response.stream.close
end
end
Streaming
WEBrick Unicorn
class MyController < ActionController::Base
include ActionController::Live
def index
100.times {
response.stream.write "hello worldn"
}
response.stream.close
end
end
Streaming
WEBrick Unicorn
Rainbows
Puma
Thin
Rails 4.0 > Node.js ?
STARE
STVARI
Cache Digest
@user
Babuška caching
@project
@project
@task
@task
@task
<%# app/views/users/show.html.erb %>
<% cache [ 'v1', @user ] do %>
<h1> <%= @user.name %> </h1>
<%= render @user.projects %>
<% end %>
<%# app/views/projects/_project.html.erb %>
<% cache [ 'v1', project ] do %>
<%= project.description %>
<%= render project.tasks %>
<% end %>
<%# app/views/tasks/_task.html.erb %>
<% cache [ 'v1', task ] do %>
Todo: <%= task.content %>
<% end %>
Babuška caching
<%# app/views/users/show.html.erb %>
<% cache [ 'v1', @user ] do %>
<h1> <%= @user.name %> </h1>
<p> Vaši projekti: </p>
<%= render @user.projects %>
<% end %>
<%# app/views/projects/_project.html.erb %>
<% cache [ 'v1', project ] do %>
<%= project.description %>
<%= render project.tasks %>
<% end %>
<%# app/views/tasks/_task.html.erb %>
<% cache [ 'v1', task ] do %>
Todo: <%= task.content %>
<% end %>
Babuška caching
<%# app/views/users/show.html.erb %>
<% cache [ 'v2', @user ] do %>
<h1> <%= @user.name %> </h1>
<p> Vaši projekti: </p>
<%= render @user.projects %>
<% end %>
<%# app/views/projects/_project.html.erb %>
<% cache [ 'v1', project ] do %>
<%= project.description %>
<%= render project.tasks %>
<% end %>
<%# app/views/tasks/_task.html.erb %>
<% cache [ 'v1', task ] do %>
Todo: <%= task.content %>
<% end %>
Babuška caching
<%# app/views/users/show.html.erb %>
<% cache [ 'v2', @user ] do %>
<h1> <%= @user.name %> </h1>
<p> Vaši projekti: </p>
<%= render @user.projects %>
<% end %>
<%# app/views/projects/_project.html.erb %>
<% cache [ 'v1', project ] do %>
<%= project.description %>
<%= render project.tasks %>
<% end %>
<%# app/views/tasks/_task.html.erb %>
<% cache [ 'v1', task ] do %>
Todo: <%= task.content %>
Date: <%= task.date %>
<% end %>
Babuška caching
<%# app/views/users/show.html.erb %>
<% cache [ 'v3', @user ] do %>
<h1> <%= @user.name %> </h1>
<p> Vaši projekti: </p>
<%= render @user.projects %>
<% end %>
<%# app/views/projects/_project.html.erb %>
<% cache [ 'v2', project ] do %>
<%= project.description %>
<%= render project.tasks %>
<% end %>
<%# app/views/tasks/_task.html.erb %>
<% cache [ 'v2', task ] do %>
Todo: <%= task.content %>
Date: <%= task.date %>
<% end %>
Babuška caching
<%# app/views/users/show.html.erb %>
<% cache @user do %>
<h1> <%= @user.name %> </h1>
<%= render @user.projects %>
<% end %>
<%# app/views/projects/_project.html.erb %>
<% cache project do %>
<%= project.description %>
<%= render project.tasks %>
<% end %>
<%# app/views/tasks/_task.html.erb %>
<% cache task do %>
Todo: <%= task.content %>
<% end %>
Sada
Čarolijom!
(+ koristi MD5 templatea i partiala
kao cache key)
Kako???
https://github.com/rails/cache_digests
Dostupan već danas!
Routing concerns
BCX::Application.routes.draw do
resources :messages { resources :comments }
resources :forwards { resources :comments }
resources :uploads { resources :comments }
end
Prije
BCX::Application.routes.draw do
concern :commentable do
resources :comments
end
resources :messages, :forwards, :uploads, concerns: :commentable
end
Sada
https://github.com/rails/routing_concerns
Dostupan već danas!
ActiveRecord::Relation
User.first
User.last
Prvi koji?
User.first
User.last
Prvi koji?
Sortirani po id-u
SELECT "users".* FROM "users" ORDER BY id LIMIT 1
Koji svi?
User.all
Vraća ActiveRecord::Relation objekt
Koji svi?
User.all
Vraća ActiveRecord::Relation objekt
@users = User.all
@users = @users.where(name: params[:name]) if params[:name]
@users = @users.order(params[:sort_by]) if params[:sort_by]
Nikoji, eto koji
User.none
Null objekt koji se dalje može ulančavati
I još
User.(metoda)!
I još
User.(metoda)!
@users = User.all
@users = @users.where(name: params[:name]) if params[:name]
@users = @users.order(params[:sort_by]) if params[:sort_by]
Prije:
I još
User.(metoda)!
@users = User.all
@users = @users.where(name: params[:name]) if params[:name]
@users = @users.order(params[:sort_by]) if params[:sort_by]
Prije:
@users = User.all
@users.where!(name: params[:name]) if params[:name]
@users.order!(params[:sort_by]) if params[:sort_by]
Sada:
ZBOGOM
STVARI
Zbogom Ruby 1.8
Zbogom
find(:all, :conditions => ...)
Zbogom
ActiveRecord:SessionStore
Zbogom
ActiveResource
Zbogom
Rails::Plugin
Zbogom
Rails::Plugin
• u /lib folder
• pretvori u gem
• Turbolinks
• Cached schema dump
• HTTP PATCH
• HTML5 helperi
• config.threadsafe!
Još STO stvari
• Rails 3.1 - gotov
• Rails 3.2 - neka deprecation upozorenja, podrška do 4.1
• Rails 4.0 - deprecation upozorenja
• Rails 4.1 - uklanjanje deprecated dijelova
Verzioniranje
Kad izlazi?
http://edgeguides.rubyonrails.org/4_0_release_notes.html
Dodatna literatura
Rails 4.0 Mind map
Boston.rb - What to expect in Rails 4.0
EdgeRails.info Blog
https://github.com/rails/rails
Dodatna dodatna literatura
Pitanja?
Hvala na pažnji!

More Related Content

PDF
AtlasCamp 2015: Using add-ons to build add-ons
PDF
BPM-2 Introduction to Advanced Workflows
PDF
BPM-1 Introduction to Advanced Workflows
PDF
BPM-3 Advanced Workflow Deep Dive
PDF
Dethroning Grunt: Simple and Effective Builds with gulp.js
PDF
Refactoring Large Web Applications with Backbone.js
PDF
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
PDF
AtlasCamp 2015: Connect everywhere - Cloud and Server
AtlasCamp 2015: Using add-ons to build add-ons
BPM-2 Introduction to Advanced Workflows
BPM-1 Introduction to Advanced Workflows
BPM-3 Advanced Workflow Deep Dive
Dethroning Grunt: Simple and Effective Builds with gulp.js
Refactoring Large Web Applications with Backbone.js
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
AtlasCamp 2015: Connect everywhere - Cloud and Server

What's hot (20)

PDF
Primefaces Nextgen Lju
PDF
实战Ecos
PDF
AtlasCamp 2015: Web technologies you should be using now
PPTX
Ruby on Rails + AngularJS + Twitter Bootstrap
PDF
devise tutorial - 2011 rubyconf taiwan
PDF
jQuery and Rails: Best Friends Forever
PPT
jQuery and AJAX with Rails
PPTX
Devise and Rails
KEY
Zazzy WordPress Navigation WordCamp Milwaukee
PDF
Keeping the frontend under control with Symfony and Webpack
PDF
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
PDF
Primefaces Confess 2012
PPTX
SPA using Rails & Backbone
PDF
Introduction to AngularJS For WordPress Developers
DOC
How to migrate Cakephp 1.x to 2.x
PDF
Using Angular with Rails
PDF
PrimeTime JSF with PrimeFaces - Dec 2014
PDF
Gae Meets Django
DOCX
multiple views and routing
DOCX
How routing works in angular js
Primefaces Nextgen Lju
实战Ecos
AtlasCamp 2015: Web technologies you should be using now
Ruby on Rails + AngularJS + Twitter Bootstrap
devise tutorial - 2011 rubyconf taiwan
jQuery and Rails: Best Friends Forever
jQuery and AJAX with Rails
Devise and Rails
Zazzy WordPress Navigation WordCamp Milwaukee
Keeping the frontend under control with Symfony and Webpack
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Primefaces Confess 2012
SPA using Rails & Backbone
Introduction to AngularJS For WordPress Developers
How to migrate Cakephp 1.x to 2.x
Using Angular with Rails
PrimeTime JSF with PrimeFaces - Dec 2014
Gae Meets Django
multiple views and routing
How routing works in angular js
Ad

Similar to WebcampZG - Rails 4 (20)

PDF
The Rails Way
PDF
Ruby on Rails : RESTful 和 Ajax
PDF
Rails 3 overview
PDF
Rails 3: Dashing to the Finish
PDF
What's new in Rails 4
PDF
Advanced RESTful Rails
PDF
Advanced RESTful Rails
KEY
More to RoC weibo
PPTX
Google app engine by example
PDF
QConSP 2015 - Dicas de Performance para Aplicações Web
PDF
Rails 2.3 and Rack - NHRuby Feb 2009
PDF
Desenvolvimento web com Ruby on Rails (parte 2)
PDF
How to disassemble one monster app into an ecosystem of 30
PDF
Angular.js Fundamentals
PDF
Ruby on Rails - Introduction
PDF
Working with Javascript in Rails
PDF
Resource and view
PDF
Ride on the Fast Track of Web with Ruby on Rails- Part 2
PDF
Intro to-rails-webperf
PDF
20130528 solution linux_frousseau_nopain_webdev
The Rails Way
Ruby on Rails : RESTful 和 Ajax
Rails 3 overview
Rails 3: Dashing to the Finish
What's new in Rails 4
Advanced RESTful Rails
Advanced RESTful Rails
More to RoC weibo
Google app engine by example
QConSP 2015 - Dicas de Performance para Aplicações Web
Rails 2.3 and Rack - NHRuby Feb 2009
Desenvolvimento web com Ruby on Rails (parte 2)
How to disassemble one monster app into an ecosystem of 30
Angular.js Fundamentals
Ruby on Rails - Introduction
Working with Javascript in Rails
Resource and view
Ride on the Fast Track of Web with Ruby on Rails- Part 2
Intro to-rails-webperf
20130528 solution linux_frousseau_nopain_webdev
Ad

WebcampZG - Rails 4