SlideShare uma empresa Scribd logo
1 de 28
Baixar para ler offline
Desenvolvimento
Web com Ruby on
Rails
João Lucas Pereira de Santana
gtalk | linkedin | twitter: jlucasps
Migration bills
@jlucasps
jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rails g
migration CreateBills
invoke active_record
create db/migrate/20130618074102_create_bills.rb
class CreateBills < ActiveRecord::Migration
def change
create_table :bills do |t|
t.column :name, :string, :null => false
t.column :description, :string
t.references :user, :foreign_key => true
t.column :date, :datetime, :null => false
t.column :value, :decimal
t.timestamps
end
end
end
Criar arquivo de migration e executá-lo
Migration bills
@jlucasps
jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rake db:migrate
== CreateBills: migrating
===============================================
=====
-- create_table(:bills)
-> 0.0073s
-- add_index(:bills, :user_id)
-> 0.0005s
== CreateBills: migrated (0.0080s)
===========================================
jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rake db:rollback
== CreateBills: reverting
===============================================
=====
-- remove_index("bills", {:column=>:user_id})
-> 0.0082s
-- drop_table("bills")
-> 0.0003s
== CreateBills: reverted (0.0088s)
===========================================
Migration bills
@jlucasps
jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rails g migration
AddIndexToBills
invoke active_record
create db/migrate/20130618080649_add_index_to_bills.rb
class AddIndexToBills < ActiveRecord::Migration
def change
add_index :bills, :user_id
end
end
Adicionar índice à foreign_key user_id da tabela bills
Migration bills
@jlucasps
jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rake db:migrate
== AddIndexToBills: migrating
================================================
-- add_index(:bills, :user_id)
-> 0.0013s
== AddIndexToBills: migrated (0.0015s)
=======================================
jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rake db:rollback
== AddIndexToBills: reverting
================================================
-- remove_index("bills", {:column=>:user_id})
-> 0.0306s
== AddIndexToBills: reverted (0.0307s)
=======================================
Model Bill
@jlucasps
class Bill < ActiveRecord::Base
# Attrs accessible
attr_accessible :name, :description, :user_id, :date, :value
# Validations
validates :name, :presence => true, :allow_blank => false
validates :user_id, :presence => true
validates :date, :presence => true
validates :value, :presence => true
# Associations
belongs_to :user
# Scopes
default_scope order("bills.date DESC")
# Públic methods
end
Model User
Alterar o model User para conter a associação com Bill
@jlucasps
class User < ActiveRecord::Base
# Attrs accessible
attr_accessible :name, :email, :age, :gender
# Constants
MALE = 1
FEMALE = 2
OTHER = 3
# Validations
validates :name, :presence => true, :allow_blank => false
validates :email, :presence => true, :allow_blank => false
validates_uniqueness_of :email
validates :gender, :presence => true, :if => :adulthood
# Associations
has_many :bills, :dependent => :destroy
# Scopes
# Públic methods
def adulthood
self.age.present? and age >= 18
end
end
Rails console
@jlucasps
jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rails console
Loading development environment (Rails 3.2.13)
irb(main):001:0> user = User.new(:name => "Joao Lucas", :email =>
"jlucasps@gmail.com")
=> #<User id: nil, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil,
created_at: nil, updated_at: nil, gender: nil>
irb(main):002:0> user.save
(0.1ms) begin transaction
User Exists (0.2ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'jlucasps@gmail.com' LIMIT
1
SQL (24.1ms) INSERT INTO "users" ("age", "created_at", "email", "gender", "name", "updated_at")
VALUES (?, ?, ?, ?, ?, ?) [["age", nil], ["created_at", Tue, 18 Jun 2013 12:52:30 UTC +00:00], ["email",
"jlucasps@gmail.com"], ["gender", nil], ["name", "Joao Lucas"], ["updated_at", Tue, 18 Jun 2013 12:52:
30 UTC +00:00]]
(422.3ms) commit transaction
=> true
irb(main):003:0>
Criar um usuário utilizando o $ rails console
Rails console
Criar 2 objetos Bill e associá-los a um usuário.
@jlucasps
irb(main):004:0> bill_1 = Bill.new :name => "Conta 1", :date => Time.
utc(2012, 06, 18), :value => 48.90
=> #<Bill id: nil, name: "Conta 1", description: nil, user_id: nil, date: "2012-06-
18 00:00:00", value: #<BigDecimal:3fc45d8,'0.489E2',18(45)>, created_at: nil,
updated_at: nil>
irb(main):012:0> bill_1.user = user
=> #<User id: 7, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil,
created_at: "2013-06-18 12:52:30", updated_at: "2013-06-18 12:52:30",
gender: nil>
irb(main):013:0> bill_1.save
(0.1ms) begin transaction
SQL (7.7ms) INSERT INTO "bills" ("created_at", "date", "description", "name", "updated_at", "user_id",
"value") VALUES (?, ?, ?, ?, ?, ?, ?) [["created_at", Tue, 18 Jun 2013 13:03:13 UTC +00:00], ["date", Mon,
18 Jun 2012 00:00:00 UTC +00:00], ["description", nil], ["name", "Conta 1"], ["updated_at", Tue, 18 Jun
2013 13:03:13 UTC +00:00], ["user_id", 7], ["value", #<BigDecimal:31e9878,'0.489E2',18(45)>]]
(413.9ms) commit transaction
=> true
Rails console
@jlucasps
irb(main):014:0> bill_2 = Bill.new :name => "Conta 2", :date => Time.
utc(2012, 06, 17), :value => 31.50
=> #<Bill id: nil, name: "Conta 2", description: nil, user_id: nil, date: "2012-06-
17 00:00:00", value: #<BigDecimal:437f150,'0.315E2',18(45)>, created_at: nil,
updated_at: nil>
irb(main):015:0> bill_2.user = user
=> #<User id: 7, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil,
created_at: "2013-06-18 12:52:30", updated_at: "2013-06-18 12:52:30",
gender: nil>
irb(main):016:0> bill_2.save
(0.1ms) begin transaction
SQL (0.7ms) INSERT INTO "bills" ("created_at", "date", "description", "name", "updated_at", "user_id",
"value") VALUES (?, ?, ?, ?, ?, ?, ?) [["created_at", Tue, 18 Jun 2013 13:05:13 UTC +00:00], ["date", Sun,
17 Jun 2012 00:00:00 UTC +00:00], ["description", nil], ["name", "Conta 2"], ["updated_at", Tue, 18 Jun
2013 13:05:13 UTC +00:00], ["user_id", 7], ["value", #<BigDecimal:3c1e0f0,'0.315E2',18(45)>]]
(427.6ms) commit transaction
=> true
Rails console
@jlucasps
irb(main):017:0> Bill.find_all_by_user_id(user.id)
Bill Load (0.3ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7
ORDER BY bills.date DESC
=> [#<Bill id: 1, name: "Conta 1", description: nil, user_id: 7, date: "2012-06-18
00:00:00", value: #<BigDecimal:46f1428,'0.489E2',18(45)>, created_at: "2013-
06-18 13:03:13", updated_at: "2013-06-18 13:03:13">, #<Bill id: 2, name:
"Conta 2", description: nil, user_id: 7, date: "2012-06-17 00:00:00", value:
#<BigDecimal:46f8048,'0.315E2',18(45)>, created_at: "2013-06-18 13:05:13",
updated_at: "2013-06-18 13:05:13">]
irb(main):018:0> Bill.find_by_user_id user.id
Bill Load (0.5ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7
ORDER BY bills.date DESC LIMIT 1
=> #<Bill id: 1, name: "Conta 1", description: nil, user_id: 7, date: "2012-06-18
00:00:00", value: #<BigDecimal:4706260,'0.489E2',18(45)>, created_at: "2013-
06-18 13:03:13", updated_at: "2013-06-18 13:03:13">
irb(main):019:0>
Rails console
@jlucasps
irb(main):020:0> Bill.where(:user_id => user.id).sum(:value)
(0.2ms) SELECT SUM("bills"."value") AS sum_id FROM "bills" WHERE
"bills"."user_id" = 7
=> #<BigDecimal:45230d8,'0.8040000000 000001E2',27(45)>
irb(main):022:0> Bill.where(:user_id => user.id, :date => Time.
utc(2012, 06, 17)).sum(:value)
(0.3ms) SELECT SUM("bills"."value") AS sum_id FROM "bills" WHERE
"bills"."user_id" = 7 AND "bills"."date" = '2012-06-17 00:00:00.000000'
=> #<BigDecimal:4a95c78,'0.315E2',18(45)>
irb(main):029:0> Bill.where(:user_id => user.id).where("bills.
date <= '2012-06-17 00:00:00.000000'").sum(:value)
(0.3ms) SELECT SUM("bills"."value") AS sum_id FROM "bills" WHERE
"bills"."user_id" = 7 AND (bills.date <= '2012-06-17 00:00:00.000000')
=> #<BigDecimal:49b44d0,'0.315E2',18(45)>
Scopes
@jlucasps
# Scopes
default_scope order("bills.date DESC")
irb(main):039:0> reload!
irb(main):040:0> user = User.find_by_email("jlucasps@gmail.com")
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" =
'jlucasps@gmail.com' LIMIT 1
=> #<User id: 7, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil,
created_at: "2013-06-18 12:52:30", updated_at: "2013-06-18 12:52:30",
gender: nil>
irb(main):041:0> user.bills
Bill Load (0.2ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7
ORDER BY bills.date DESC
=> [#<Bill id: 1, name: "Conta 1", description: nil, user_id: 7, date: "2012-
06-18 00:00:00", value: #<BigDecimal:2d11fd0,'0.489E2',18(45)>,
created_at: "2013-06-18 13:03:13", updated_at: "2013-06-18 13:03:13">,
#<Bill id: 2, name: "Conta 2", description: nil, user_id: 7, date: "2012-06-17
00:00:00", value: #<BigDecimal:3d120b0,'0.315E2',18(45)>, created_at:
"2013-06-18 13:05:13", updated_at: "2013-06-18 13:05:13">]
Scopes
@jlucasps
# Scopes
default_scope order("bills.date ASC")
irb(main):044:0> reload!
Reloading...
=> true
irb(main):045:0> user = User.find_by_email("jlucasps@gmail.com")
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" =
'jlucasps@gmail.com' LIMIT 1
=> #<User id: 7, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil, created_at:
"2013-06-18 12:52:30", updated_at: "2013-06-18 12:52:30", gender: nil>
irb(main):046:0> user.bills
Bill Load (0.1ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7 ORDER BY
bills.date ASC
=> [#<Bill id: 2, name: "Conta 2", description: nil, user_id: 7, date: "2012-06-17 00:
00:00", value: #<BigDecimal:4971270,'0.315E2',18(45)>, created_at: "2013-06-18 13:
05:13", updated_at: "2013-06-18 13:05:13">, #<Bill id: 1, name: "Conta 1", description:
nil, user_id: 7, date: "2012-06-18 00:00:00", value: #<BigDecimal:4977eb8,'0.489E2',
18(45)>, created_at: "2013-06-18 13:03:13", updated_at: "2013-06-18 13:03:13">]
Scopes
@jlucasps
irb(main):051:0> reload!
irb(main):052:0> user = User.find_by_email("jlucasps@gmail.com")
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'jlucasps@gmail.com' LIMIT 1
=> #<User id: 7, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil, created_at: "2013-06-18 12:
52:30", updated_at: "2013-06-18 12:52:30", gender: nil>
irb(main):053:0> user.bills
Bill Load (0.1ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7 ORDER BY bills.date DESC
=> [#<Bill id: 1, name: "Conta 1", description: nil, user_id: 7, date: "2012-06-18 00:00:00", value:
#<BigDecimal:49105b0,'0.489E2',18(45)>, created_at: "2013-06-18 13:03:13", updated_at: "2013-06-18
13:03:13">, #<Bill id: 2, name: "Conta 2", description: nil, user_id: 7, date: "2012-06-17 00:00:00", value:
#<BigDecimal:491b050,'0.315E2',18(45)>, created_at: "2013-06-18 13:05:13", updated_at: "2013-06-18
13:05:13">]
irb(main):054:0> user.bills.recents
Bill Load (0.4ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7 ORDER BY bills.date DESC
LIMIT 5
=> [#<Bill id: 1, name: "Conta 1", description: nil, user_id: 7, date: "2012-06-18 00:00:00", value:
#<BigDecimal:4938560,'0.489E2',18(45)>, created_at: "2013-06-18 13:03:13", updated_at: "2013-06-18
13:03:13">, #<Bill id: 2, name: "Conta 2", description: nil, user_id: 7, date: "2012-06-17 00:00:00", value:
#<BigDecimal:49368f0,'0.315E2',18(45)>, created_at: "2013-06-18 13:05:13", updated_at: "2013-06-18
13:05:13">]
# Scopes
default_scope order("bills.date DESC")
scope :recents, order("bills.date DESC").limit(5)
Scopes
@jlucasps
irb(main):058:0> reload!
irb(main):059:0> user = User.find_by_email("jlucasps@gmail.com")
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" =
'jlucasps@gmail.com' LIMIT 1
=> #<User id: 7, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil,
created_at: "2013-06-18 12:52:30", updated_at: "2013-06-18 12:52:30", gender:
nil>
irb(main):060:0> user.bills.recents_by_date Time.utc(2012, 06, 17)
Bill Load (0.3ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7 AND
(bills.date <= '2012-06-17 00:00:00.000000') ORDER BY bills.date DESC LIMIT 5
=> [#<Bill id: 2, name: "Conta 2", description: nil, user_id: 7, date: "2012-06-17
00:00:00", value: #<BigDecimal:4b07e90,'0.315E2',18(45)>, created_at: "2013-
06-18 13:05:13", updated_at: "2013-06-18 13:05:13">]
scope :recents, order("bills.date DESC").limit(5)
scope :recents_by_date, lambda {|date|
where("bills.date <= '#{date.strftime('%Y-%m-%d %H:%M:%S.000000')}'").order
("bills.date DESC").limit(5)
}
Commit
$ git add .
$ git commit -m "Criação de scopes"
Agora vamos adicionar relacionamentos entre
as rotas de Usuários e Contas
@jlucasps
...
resources :users do
resources :bills
end
...
Bills
@jlucasps
Alterar view de show do modelo user: /app/views/users/show.html.erb
<p id="notice"><%= notice %></p>
<p><b>Nome:</b><%= @user.name %></p>
<p><b>email:</b><%= @user.email %></p>
<p><b>Idade:</b><%= @user.age %></p>
<p><b>Sexo:</b><%= @user.gender %></p>
<div id='new_bill'>
<%= render :partial => 'bills/new', :locals => {:bill => Bill.new, :user => @user} %>
</div>
<div id='bills'>
<%= render :partial => 'bills/index', :locals => {:bills => @user.bills} %>
</div>
<%= link_to 'Edit', edit_user_path(@user), :class => "btn" %> |
<%= link_to 'Back', users_path, :class => "btn" %>
Bills
@jlucasps
Criar partial para lista contas: /app/views/bills/_index.html.erb
<% if bills.any? %>
<% bills.each do |bill| %>
<div class='well well-small'>
<h4><%= bill.name %></h4>
<%= bill.description %>
<h5><%= l(bill.date, :forma => :long) %></h5>
<h3><%= bill.value.round(2) %></h3>
</div>
<% end %>
<% else %>
<div class='alert'>
<%= t('no_bill_registered_to_this_user') %>
</div>
<% end %>
Bills
@jlucasps
Criar partial com formulário de nova conta: /app/views/bills/_new.html.erb
<hr>
<h4><%= t('new_bill') %></h4>
<%= form_for([user, bill], :remote => true) do |f| %>
<%= render :partial => 'shared/error_messages' , :locals => {:resource => bill} %
>
<%= f.hidden_field :user_id, :value => user.id %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :description %>
<%= f.text_field :description %>
<%= f.label :date %>
<%= f.text_field :date %>
<%= f.label :value %>
<%= f.text_field :value %>
<% end %>
Bills
@jlucasps
Criar controller bills e action create
class BillsController < ApplicationController
def create
@bill = Bill.new(params[:bill])
flash[:notice] = (@bill.save ? t('saved_successfully') : t('error_while_saving'))
end
end
Bills
@jlucasps
Criar view create /app/views/bills/create.js.erb
<% if @bill.persisted? %>
$("#bills").html("<%= j(render :partial => 'bills/index', :locals => {:
bills => @bill.user.bills}) %>");
$("#bills").prepend("<%= j notice %>");
$("#new_bill").html("<%= j(render :partial => 'bills/new', :locals =>
{:bill => Bill.new, :user => @bill.user} ) %>");
<% else %>
$("#new_bill").html("<%= j(render :partial => 'bills/new', :locals =>
{:bill => @bill, :user => @bill.user}) %>");
<% end %>
Bills
@jlucasps
Alterar view de index para apresentar link para edit e destroy
<hr>
<h4><%= t('bills') %></h4>
<% if bills.any? %>
<% bills.each do |bill| %>
<div id='bill_<%= bill.id %>' class='well well-small'>
<h4><%= bill.name %></h4>
<%= bill.description %>
<h5><%= l(bill.date, :forma => :long) %></h5>
<h3><%= bill.value.round(2) %></h3>
<%= link_to t('edit'), edit_user_bill_path(bill.user, bill), :class => "btn btn-
primary", :remote => true %>
<%= link_to t('delete'), [bill.user, bill], :remote => true, :method => :delete, :
class => "btn btn-danger" %>
</div>
<% end %>
<% else %>
<div class='alert'>
<%= t('no_bill_registered_to_this_user') %>
</div>
<% end %>
Bills
@jlucasps
Criar action e view destroy
def destroy
@bill = Bill.find(params[:id])
@bill.destroy
end
<% if @bill.destroyed? %>
$("#bill_<%= @bill.id %>").remove();
<% else %>
$("#bill_<%= @bill.id %>").prepend("<%= t
('error_while_deleting') %>");
<% end %>
Bills
@jlucasps
Criar action e view edit
def edit
@bill = Bill.find(params[:id])
end
$("#new_bill").html("<%= j(render :partial => 'bills/new', :
locals => {:bill => @bill, :user => @bill.user}) %>");
$('html, body').animate({scrollTop: $("#new_bill").offset().
top});
Bills
@jlucasps
Implementar action e view de update
def update
@bill = Bill.find(params[:id])
flash[:notice] = (@bill.update_attributes(params[:bill]) ? t
('updated_successfully') : t('error_while_updating'))
end
<% if @bill.valid? %>
$("#bills").html("<%= j(render :partial => 'bills/index', :locals => {:bills =>
@bill.user.bills}) %>");
$("#bills").prepend("<%= j notice %>");
$("#new_bill").html("<%= j(render :partial => 'bills/new', :locals => {:bill
=> Bill.new, :user => @bill.user} ) %>");
<% else %>
$("#new_bill").html("<%= j(render :partial => 'bills/new', :locals => {:bill
=> @bill, :user => @bill.user}) %>");
<% end %>
Bills
@jlucasps
Desenvolvimento
Web com Ruby on
Rails
João Lucas Pereira de Santana
gtalk | linkedin | twitter: jlucasps
Obrigado!

Mais conteúdo relacionado

Mais procurados

Basic crud operation
Basic crud operationBasic crud operation
Basic crud operationzarigatongy
 
The Ring programming language version 1.8 book - Part 49 of 202
The Ring programming language version 1.8 book - Part 49 of 202The Ring programming language version 1.8 book - Part 49 of 202
The Ring programming language version 1.8 book - Part 49 of 202Mahmoud Samir Fayed
 
Hi5 Opensocial Code Lab Presentation
Hi5 Opensocial Code Lab PresentationHi5 Opensocial Code Lab Presentation
Hi5 Opensocial Code Lab Presentationplindner
 
The Ring programming language version 1.5.1 book - Part 42 of 180
The Ring programming language version 1.5.1 book - Part 42 of 180The Ring programming language version 1.5.1 book - Part 42 of 180
The Ring programming language version 1.5.1 book - Part 42 of 180Mahmoud Samir Fayed
 
MongoD Essentials
MongoD EssentialsMongoD Essentials
MongoD Essentialszahid-mian
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationMongoDB
 
Powering Systems of Engagement
Powering Systems of EngagementPowering Systems of Engagement
Powering Systems of EngagementMongoDB
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB
 
De normalised london aggregation framework overview
De normalised london  aggregation framework overview De normalised london  aggregation framework overview
De normalised london aggregation framework overview Chris Harris
 
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...MongoDB
 
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"South Tyrol Free Software Conference
 
Using Change Streams to Keep Up with Your Data
Using Change Streams to Keep Up with Your DataUsing Change Streams to Keep Up with Your Data
Using Change Streams to Keep Up with Your DataEvan Rodd
 
The rise of json in rdbms land jab17
The rise of json in rdbms land jab17The rise of json in rdbms land jab17
The rise of json in rdbms land jab17alikonweb
 
1140 p2 p04_and_1350_p2p05_and_1440_p2p06
1140 p2 p04_and_1350_p2p05_and_1440_p2p061140 p2 p04_and_1350_p2p05_and_1440_p2p06
1140 p2 p04_and_1350_p2p05_and_1440_p2p06MongoDB
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015NoSQLmatters
 

Mais procurados (20)

Basic crud operation
Basic crud operationBasic crud operation
Basic crud operation
 
The Ring programming language version 1.8 book - Part 49 of 202
The Ring programming language version 1.8 book - Part 49 of 202The Ring programming language version 1.8 book - Part 49 of 202
The Ring programming language version 1.8 book - Part 49 of 202
 
Hi5 Opensocial Code Lab Presentation
Hi5 Opensocial Code Lab PresentationHi5 Opensocial Code Lab Presentation
Hi5 Opensocial Code Lab Presentation
 
Ushahidi
UshahidiUshahidi
Ushahidi
 
The Ring programming language version 1.5.1 book - Part 42 of 180
The Ring programming language version 1.5.1 book - Part 42 of 180The Ring programming language version 1.5.1 book - Part 42 of 180
The Ring programming language version 1.5.1 book - Part 42 of 180
 
MongoD Essentials
MongoD EssentialsMongoD Essentials
MongoD Essentials
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
 
jQuery's Secrets
jQuery's SecretsjQuery's Secrets
jQuery's Secrets
 
Powering Systems of Engagement
Powering Systems of EngagementPowering Systems of Engagement
Powering Systems of Engagement
 
Advanced MongoDB #1
Advanced MongoDB #1Advanced MongoDB #1
Advanced MongoDB #1
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB Performance
 
PhoneGap: Local Storage
PhoneGap: Local StoragePhoneGap: Local Storage
PhoneGap: Local Storage
 
De normalised london aggregation framework overview
De normalised london  aggregation framework overview De normalised london  aggregation framework overview
De normalised london aggregation framework overview
 
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
 
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
SFScon17 - Patrick Puecher: "Exploring data with Elasticsearch and Kibana"
 
Using Change Streams to Keep Up with Your Data
Using Change Streams to Keep Up with Your DataUsing Change Streams to Keep Up with Your Data
Using Change Streams to Keep Up with Your Data
 
The rise of json in rdbms land jab17
The rise of json in rdbms land jab17The rise of json in rdbms land jab17
The rise of json in rdbms land jab17
 
1140 p2 p04_and_1350_p2p05_and_1440_p2p06
1140 p2 p04_and_1350_p2p05_and_1440_p2p061140 p2 p04_and_1350_p2p05_and_1440_p2p06
1140 p2 p04_and_1350_p2p05_and_1440_p2p06
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
 

Destaque

Critical Rendering Path - Velocidade também é uma funcionalidade
Critical Rendering Path - Velocidade também é uma funcionalidadeCritical Rendering Path - Velocidade também é uma funcionalidade
Critical Rendering Path - Velocidade também é uma funcionalidadeJoao Lucas Santana
 
V. Alagueva
V. AlaguevaV. Alagueva
V. Alaguevasoshi3
 
Um roadmap do Framework Ruby on Rails, do Rails 1 ao Rails 4 - DevDay 2013
Um roadmap do Framework Ruby on Rails, do Rails 1 ao Rails 4 - DevDay 2013Um roadmap do Framework Ruby on Rails, do Rails 1 ao Rails 4 - DevDay 2013
Um roadmap do Framework Ruby on Rails, do Rails 1 ao Rails 4 - DevDay 2013Joao Lucas Santana
 
K dokladu
K dokladuK dokladu
K dokladusoshi3
 
anonimoys
anonimoysanonimoys
anonimoysjohn4cx
 

Destaque (6)

Critical Rendering Path - Velocidade também é uma funcionalidade
Critical Rendering Path - Velocidade também é uma funcionalidadeCritical Rendering Path - Velocidade também é uma funcionalidade
Critical Rendering Path - Velocidade também é uma funcionalidade
 
V. Alagueva
V. AlaguevaV. Alagueva
V. Alagueva
 
Um roadmap do Framework Ruby on Rails, do Rails 1 ao Rails 4 - DevDay 2013
Um roadmap do Framework Ruby on Rails, do Rails 1 ao Rails 4 - DevDay 2013Um roadmap do Framework Ruby on Rails, do Rails 1 ao Rails 4 - DevDay 2013
Um roadmap do Framework Ruby on Rails, do Rails 1 ao Rails 4 - DevDay 2013
 
K dokladu
K dokladuK dokladu
K dokladu
 
anonimoys
anonimoysanonimoys
anonimoys
 
Lcd samsung sp20 so la20s51b
Lcd samsung sp20 so la20s51bLcd samsung sp20 so la20s51b
Lcd samsung sp20 so la20s51b
 

Semelhante a Desenvolvimento web com Ruby on Rails (parte 5)

Desenvolvimento web com Ruby on Rails (parte 3)
Desenvolvimento web com Ruby on Rails (parte 3)Desenvolvimento web com Ruby on Rails (parte 3)
Desenvolvimento web com Ruby on Rails (parte 3)Joao Lucas Santana
 
How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6Maxime Beugnet
 
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Alex Sharp
 
Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)MongoSF
 
Practical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFPractical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFAlex Sharp
 
2011 05-23 metrics-agilasverige-english
2011 05-23 metrics-agilasverige-english2011 05-23 metrics-agilasverige-english
2011 05-23 metrics-agilasverige-englishMårten Gustafson
 
IOOF IT System Modernisation
IOOF IT System ModernisationIOOF IT System Modernisation
IOOF IT System ModernisationMongoDB
 
Building decentralised apps with js - Devoxx Morocco 2018
Building decentralised apps with js - Devoxx Morocco 2018Building decentralised apps with js - Devoxx Morocco 2018
Building decentralised apps with js - Devoxx Morocco 2018Mikhail Kuznetcov
 
[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data
[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data
[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your DataMongoDB
 
Practical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbPractical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbAlex Sharp
 
Back to Basics 2017 - Your First MongoDB Application
Back to Basics 2017 - Your First MongoDB ApplicationBack to Basics 2017 - Your First MongoDB Application
Back to Basics 2017 - Your First MongoDB ApplicationJoe Drumgoole
 
IBM Db2 JSON 11.5
IBM  Db2 JSON 11.5IBM  Db2 JSON 11.5
IBM Db2 JSON 11.5Phil Downey
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningPuneet Behl
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionJesus Manuel Olivas
 
Mongo db world 2014 billrun
Mongo db world 2014   billrunMongo db world 2014   billrun
Mongo db world 2014 billrunMongoDB
 
MongoDB for Analytics
MongoDB for AnalyticsMongoDB for Analytics
MongoDB for AnalyticsMongoDB
 
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...sriram sarwan
 
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)Dan Robinson
 
Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007Rabble .
 

Semelhante a Desenvolvimento web com Ruby on Rails (parte 5) (20)

Desenvolvimento web com Ruby on Rails (parte 3)
Desenvolvimento web com Ruby on Rails (parte 3)Desenvolvimento web com Ruby on Rails (parte 3)
Desenvolvimento web com Ruby on Rails (parte 3)
 
How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6
 
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
 
Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)
 
Practical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFPractical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSF
 
2011 05-23 metrics-agilasverige-english
2011 05-23 metrics-agilasverige-english2011 05-23 metrics-agilasverige-english
2011 05-23 metrics-agilasverige-english
 
IOOF IT System Modernisation
IOOF IT System ModernisationIOOF IT System Modernisation
IOOF IT System Modernisation
 
Building decentralised apps with js - Devoxx Morocco 2018
Building decentralised apps with js - Devoxx Morocco 2018Building decentralised apps with js - Devoxx Morocco 2018
Building decentralised apps with js - Devoxx Morocco 2018
 
[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data
[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data
[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data
 
Practical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbPractical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo Db
 
Back to Basics 2017 - Your First MongoDB Application
Back to Basics 2017 - Your First MongoDB ApplicationBack to Basics 2017 - Your First MongoDB Application
Back to Basics 2017 - Your First MongoDB Application
 
IBM Db2 JSON 11.5
IBM  Db2 JSON 11.5IBM  Db2 JSON 11.5
IBM Db2 JSON 11.5
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 Edition
 
Mongo db world 2014 billrun
Mongo db world 2014   billrunMongo db world 2014   billrun
Mongo db world 2014 billrun
 
MongoDB for Analytics
MongoDB for AnalyticsMongoDB for Analytics
MongoDB for Analytics
 
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
Cbsecomputersciencecclass12boardproject bankmanagmentsystem-180703065625-conv...
 
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
 
Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007
 
MongoDB
MongoDBMongoDB
MongoDB
 

Último

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Último (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Desenvolvimento web com Ruby on Rails (parte 5)

  • 1. Desenvolvimento Web com Ruby on Rails João Lucas Pereira de Santana gtalk | linkedin | twitter: jlucasps
  • 2. Migration bills @jlucasps jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rails g migration CreateBills invoke active_record create db/migrate/20130618074102_create_bills.rb class CreateBills < ActiveRecord::Migration def change create_table :bills do |t| t.column :name, :string, :null => false t.column :description, :string t.references :user, :foreign_key => true t.column :date, :datetime, :null => false t.column :value, :decimal t.timestamps end end end Criar arquivo de migration e executá-lo
  • 3. Migration bills @jlucasps jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rake db:migrate == CreateBills: migrating =============================================== ===== -- create_table(:bills) -> 0.0073s -- add_index(:bills, :user_id) -> 0.0005s == CreateBills: migrated (0.0080s) =========================================== jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rake db:rollback == CreateBills: reverting =============================================== ===== -- remove_index("bills", {:column=>:user_id}) -> 0.0082s -- drop_table("bills") -> 0.0003s == CreateBills: reverted (0.0088s) ===========================================
  • 4. Migration bills @jlucasps jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rails g migration AddIndexToBills invoke active_record create db/migrate/20130618080649_add_index_to_bills.rb class AddIndexToBills < ActiveRecord::Migration def change add_index :bills, :user_id end end Adicionar índice à foreign_key user_id da tabela bills
  • 5. Migration bills @jlucasps jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rake db:migrate == AddIndexToBills: migrating ================================================ -- add_index(:bills, :user_id) -> 0.0013s == AddIndexToBills: migrated (0.0015s) ======================================= jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rake db:rollback == AddIndexToBills: reverting ================================================ -- remove_index("bills", {:column=>:user_id}) -> 0.0306s == AddIndexToBills: reverted (0.0307s) =======================================
  • 6. Model Bill @jlucasps class Bill < ActiveRecord::Base # Attrs accessible attr_accessible :name, :description, :user_id, :date, :value # Validations validates :name, :presence => true, :allow_blank => false validates :user_id, :presence => true validates :date, :presence => true validates :value, :presence => true # Associations belongs_to :user # Scopes default_scope order("bills.date DESC") # Públic methods end
  • 7. Model User Alterar o model User para conter a associação com Bill @jlucasps class User < ActiveRecord::Base # Attrs accessible attr_accessible :name, :email, :age, :gender # Constants MALE = 1 FEMALE = 2 OTHER = 3 # Validations validates :name, :presence => true, :allow_blank => false validates :email, :presence => true, :allow_blank => false validates_uniqueness_of :email validates :gender, :presence => true, :if => :adulthood # Associations has_many :bills, :dependent => :destroy # Scopes # Públic methods def adulthood self.age.present? and age >= 18 end end
  • 8. Rails console @jlucasps jlucasps@lotus:/media/truecrypt1/handsonrails/first_app$ rails console Loading development environment (Rails 3.2.13) irb(main):001:0> user = User.new(:name => "Joao Lucas", :email => "jlucasps@gmail.com") => #<User id: nil, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil, created_at: nil, updated_at: nil, gender: nil> irb(main):002:0> user.save (0.1ms) begin transaction User Exists (0.2ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'jlucasps@gmail.com' LIMIT 1 SQL (24.1ms) INSERT INTO "users" ("age", "created_at", "email", "gender", "name", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["age", nil], ["created_at", Tue, 18 Jun 2013 12:52:30 UTC +00:00], ["email", "jlucasps@gmail.com"], ["gender", nil], ["name", "Joao Lucas"], ["updated_at", Tue, 18 Jun 2013 12:52: 30 UTC +00:00]] (422.3ms) commit transaction => true irb(main):003:0> Criar um usuário utilizando o $ rails console
  • 9. Rails console Criar 2 objetos Bill e associá-los a um usuário. @jlucasps irb(main):004:0> bill_1 = Bill.new :name => "Conta 1", :date => Time. utc(2012, 06, 18), :value => 48.90 => #<Bill id: nil, name: "Conta 1", description: nil, user_id: nil, date: "2012-06- 18 00:00:00", value: #<BigDecimal:3fc45d8,'0.489E2',18(45)>, created_at: nil, updated_at: nil> irb(main):012:0> bill_1.user = user => #<User id: 7, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil, created_at: "2013-06-18 12:52:30", updated_at: "2013-06-18 12:52:30", gender: nil> irb(main):013:0> bill_1.save (0.1ms) begin transaction SQL (7.7ms) INSERT INTO "bills" ("created_at", "date", "description", "name", "updated_at", "user_id", "value") VALUES (?, ?, ?, ?, ?, ?, ?) [["created_at", Tue, 18 Jun 2013 13:03:13 UTC +00:00], ["date", Mon, 18 Jun 2012 00:00:00 UTC +00:00], ["description", nil], ["name", "Conta 1"], ["updated_at", Tue, 18 Jun 2013 13:03:13 UTC +00:00], ["user_id", 7], ["value", #<BigDecimal:31e9878,'0.489E2',18(45)>]] (413.9ms) commit transaction => true
  • 10. Rails console @jlucasps irb(main):014:0> bill_2 = Bill.new :name => "Conta 2", :date => Time. utc(2012, 06, 17), :value => 31.50 => #<Bill id: nil, name: "Conta 2", description: nil, user_id: nil, date: "2012-06- 17 00:00:00", value: #<BigDecimal:437f150,'0.315E2',18(45)>, created_at: nil, updated_at: nil> irb(main):015:0> bill_2.user = user => #<User id: 7, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil, created_at: "2013-06-18 12:52:30", updated_at: "2013-06-18 12:52:30", gender: nil> irb(main):016:0> bill_2.save (0.1ms) begin transaction SQL (0.7ms) INSERT INTO "bills" ("created_at", "date", "description", "name", "updated_at", "user_id", "value") VALUES (?, ?, ?, ?, ?, ?, ?) [["created_at", Tue, 18 Jun 2013 13:05:13 UTC +00:00], ["date", Sun, 17 Jun 2012 00:00:00 UTC +00:00], ["description", nil], ["name", "Conta 2"], ["updated_at", Tue, 18 Jun 2013 13:05:13 UTC +00:00], ["user_id", 7], ["value", #<BigDecimal:3c1e0f0,'0.315E2',18(45)>]] (427.6ms) commit transaction => true
  • 11. Rails console @jlucasps irb(main):017:0> Bill.find_all_by_user_id(user.id) Bill Load (0.3ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7 ORDER BY bills.date DESC => [#<Bill id: 1, name: "Conta 1", description: nil, user_id: 7, date: "2012-06-18 00:00:00", value: #<BigDecimal:46f1428,'0.489E2',18(45)>, created_at: "2013- 06-18 13:03:13", updated_at: "2013-06-18 13:03:13">, #<Bill id: 2, name: "Conta 2", description: nil, user_id: 7, date: "2012-06-17 00:00:00", value: #<BigDecimal:46f8048,'0.315E2',18(45)>, created_at: "2013-06-18 13:05:13", updated_at: "2013-06-18 13:05:13">] irb(main):018:0> Bill.find_by_user_id user.id Bill Load (0.5ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7 ORDER BY bills.date DESC LIMIT 1 => #<Bill id: 1, name: "Conta 1", description: nil, user_id: 7, date: "2012-06-18 00:00:00", value: #<BigDecimal:4706260,'0.489E2',18(45)>, created_at: "2013- 06-18 13:03:13", updated_at: "2013-06-18 13:03:13"> irb(main):019:0>
  • 12. Rails console @jlucasps irb(main):020:0> Bill.where(:user_id => user.id).sum(:value) (0.2ms) SELECT SUM("bills"."value") AS sum_id FROM "bills" WHERE "bills"."user_id" = 7 => #<BigDecimal:45230d8,'0.8040000000 000001E2',27(45)> irb(main):022:0> Bill.where(:user_id => user.id, :date => Time. utc(2012, 06, 17)).sum(:value) (0.3ms) SELECT SUM("bills"."value") AS sum_id FROM "bills" WHERE "bills"."user_id" = 7 AND "bills"."date" = '2012-06-17 00:00:00.000000' => #<BigDecimal:4a95c78,'0.315E2',18(45)> irb(main):029:0> Bill.where(:user_id => user.id).where("bills. date <= '2012-06-17 00:00:00.000000'").sum(:value) (0.3ms) SELECT SUM("bills"."value") AS sum_id FROM "bills" WHERE "bills"."user_id" = 7 AND (bills.date <= '2012-06-17 00:00:00.000000') => #<BigDecimal:49b44d0,'0.315E2',18(45)>
  • 13. Scopes @jlucasps # Scopes default_scope order("bills.date DESC") irb(main):039:0> reload! irb(main):040:0> user = User.find_by_email("jlucasps@gmail.com") User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'jlucasps@gmail.com' LIMIT 1 => #<User id: 7, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil, created_at: "2013-06-18 12:52:30", updated_at: "2013-06-18 12:52:30", gender: nil> irb(main):041:0> user.bills Bill Load (0.2ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7 ORDER BY bills.date DESC => [#<Bill id: 1, name: "Conta 1", description: nil, user_id: 7, date: "2012- 06-18 00:00:00", value: #<BigDecimal:2d11fd0,'0.489E2',18(45)>, created_at: "2013-06-18 13:03:13", updated_at: "2013-06-18 13:03:13">, #<Bill id: 2, name: "Conta 2", description: nil, user_id: 7, date: "2012-06-17 00:00:00", value: #<BigDecimal:3d120b0,'0.315E2',18(45)>, created_at: "2013-06-18 13:05:13", updated_at: "2013-06-18 13:05:13">]
  • 14. Scopes @jlucasps # Scopes default_scope order("bills.date ASC") irb(main):044:0> reload! Reloading... => true irb(main):045:0> user = User.find_by_email("jlucasps@gmail.com") User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'jlucasps@gmail.com' LIMIT 1 => #<User id: 7, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil, created_at: "2013-06-18 12:52:30", updated_at: "2013-06-18 12:52:30", gender: nil> irb(main):046:0> user.bills Bill Load (0.1ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7 ORDER BY bills.date ASC => [#<Bill id: 2, name: "Conta 2", description: nil, user_id: 7, date: "2012-06-17 00: 00:00", value: #<BigDecimal:4971270,'0.315E2',18(45)>, created_at: "2013-06-18 13: 05:13", updated_at: "2013-06-18 13:05:13">, #<Bill id: 1, name: "Conta 1", description: nil, user_id: 7, date: "2012-06-18 00:00:00", value: #<BigDecimal:4977eb8,'0.489E2', 18(45)>, created_at: "2013-06-18 13:03:13", updated_at: "2013-06-18 13:03:13">]
  • 15. Scopes @jlucasps irb(main):051:0> reload! irb(main):052:0> user = User.find_by_email("jlucasps@gmail.com") User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'jlucasps@gmail.com' LIMIT 1 => #<User id: 7, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil, created_at: "2013-06-18 12: 52:30", updated_at: "2013-06-18 12:52:30", gender: nil> irb(main):053:0> user.bills Bill Load (0.1ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7 ORDER BY bills.date DESC => [#<Bill id: 1, name: "Conta 1", description: nil, user_id: 7, date: "2012-06-18 00:00:00", value: #<BigDecimal:49105b0,'0.489E2',18(45)>, created_at: "2013-06-18 13:03:13", updated_at: "2013-06-18 13:03:13">, #<Bill id: 2, name: "Conta 2", description: nil, user_id: 7, date: "2012-06-17 00:00:00", value: #<BigDecimal:491b050,'0.315E2',18(45)>, created_at: "2013-06-18 13:05:13", updated_at: "2013-06-18 13:05:13">] irb(main):054:0> user.bills.recents Bill Load (0.4ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7 ORDER BY bills.date DESC LIMIT 5 => [#<Bill id: 1, name: "Conta 1", description: nil, user_id: 7, date: "2012-06-18 00:00:00", value: #<BigDecimal:4938560,'0.489E2',18(45)>, created_at: "2013-06-18 13:03:13", updated_at: "2013-06-18 13:03:13">, #<Bill id: 2, name: "Conta 2", description: nil, user_id: 7, date: "2012-06-17 00:00:00", value: #<BigDecimal:49368f0,'0.315E2',18(45)>, created_at: "2013-06-18 13:05:13", updated_at: "2013-06-18 13:05:13">] # Scopes default_scope order("bills.date DESC") scope :recents, order("bills.date DESC").limit(5)
  • 16. Scopes @jlucasps irb(main):058:0> reload! irb(main):059:0> user = User.find_by_email("jlucasps@gmail.com") User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'jlucasps@gmail.com' LIMIT 1 => #<User id: 7, name: "Joao Lucas", email: "jlucasps@gmail.com", age: nil, created_at: "2013-06-18 12:52:30", updated_at: "2013-06-18 12:52:30", gender: nil> irb(main):060:0> user.bills.recents_by_date Time.utc(2012, 06, 17) Bill Load (0.3ms) SELECT "bills".* FROM "bills" WHERE "bills"."user_id" = 7 AND (bills.date <= '2012-06-17 00:00:00.000000') ORDER BY bills.date DESC LIMIT 5 => [#<Bill id: 2, name: "Conta 2", description: nil, user_id: 7, date: "2012-06-17 00:00:00", value: #<BigDecimal:4b07e90,'0.315E2',18(45)>, created_at: "2013- 06-18 13:05:13", updated_at: "2013-06-18 13:05:13">] scope :recents, order("bills.date DESC").limit(5) scope :recents_by_date, lambda {|date| where("bills.date <= '#{date.strftime('%Y-%m-%d %H:%M:%S.000000')}'").order ("bills.date DESC").limit(5) }
  • 17. Commit $ git add . $ git commit -m "Criação de scopes" Agora vamos adicionar relacionamentos entre as rotas de Usuários e Contas @jlucasps ... resources :users do resources :bills end ...
  • 18. Bills @jlucasps Alterar view de show do modelo user: /app/views/users/show.html.erb <p id="notice"><%= notice %></p> <p><b>Nome:</b><%= @user.name %></p> <p><b>email:</b><%= @user.email %></p> <p><b>Idade:</b><%= @user.age %></p> <p><b>Sexo:</b><%= @user.gender %></p> <div id='new_bill'> <%= render :partial => 'bills/new', :locals => {:bill => Bill.new, :user => @user} %> </div> <div id='bills'> <%= render :partial => 'bills/index', :locals => {:bills => @user.bills} %> </div> <%= link_to 'Edit', edit_user_path(@user), :class => "btn" %> | <%= link_to 'Back', users_path, :class => "btn" %>
  • 19. Bills @jlucasps Criar partial para lista contas: /app/views/bills/_index.html.erb <% if bills.any? %> <% bills.each do |bill| %> <div class='well well-small'> <h4><%= bill.name %></h4> <%= bill.description %> <h5><%= l(bill.date, :forma => :long) %></h5> <h3><%= bill.value.round(2) %></h3> </div> <% end %> <% else %> <div class='alert'> <%= t('no_bill_registered_to_this_user') %> </div> <% end %>
  • 20. Bills @jlucasps Criar partial com formulário de nova conta: /app/views/bills/_new.html.erb <hr> <h4><%= t('new_bill') %></h4> <%= form_for([user, bill], :remote => true) do |f| %> <%= render :partial => 'shared/error_messages' , :locals => {:resource => bill} % > <%= f.hidden_field :user_id, :value => user.id %> <%= f.label :name %> <%= f.text_field :name %> <%= f.label :description %> <%= f.text_field :description %> <%= f.label :date %> <%= f.text_field :date %> <%= f.label :value %> <%= f.text_field :value %> <% end %>
  • 21. Bills @jlucasps Criar controller bills e action create class BillsController < ApplicationController def create @bill = Bill.new(params[:bill]) flash[:notice] = (@bill.save ? t('saved_successfully') : t('error_while_saving')) end end
  • 22. Bills @jlucasps Criar view create /app/views/bills/create.js.erb <% if @bill.persisted? %> $("#bills").html("<%= j(render :partial => 'bills/index', :locals => {: bills => @bill.user.bills}) %>"); $("#bills").prepend("<%= j notice %>"); $("#new_bill").html("<%= j(render :partial => 'bills/new', :locals => {:bill => Bill.new, :user => @bill.user} ) %>"); <% else %> $("#new_bill").html("<%= j(render :partial => 'bills/new', :locals => {:bill => @bill, :user => @bill.user}) %>"); <% end %>
  • 23. Bills @jlucasps Alterar view de index para apresentar link para edit e destroy <hr> <h4><%= t('bills') %></h4> <% if bills.any? %> <% bills.each do |bill| %> <div id='bill_<%= bill.id %>' class='well well-small'> <h4><%= bill.name %></h4> <%= bill.description %> <h5><%= l(bill.date, :forma => :long) %></h5> <h3><%= bill.value.round(2) %></h3> <%= link_to t('edit'), edit_user_bill_path(bill.user, bill), :class => "btn btn- primary", :remote => true %> <%= link_to t('delete'), [bill.user, bill], :remote => true, :method => :delete, : class => "btn btn-danger" %> </div> <% end %> <% else %> <div class='alert'> <%= t('no_bill_registered_to_this_user') %> </div> <% end %>
  • 24. Bills @jlucasps Criar action e view destroy def destroy @bill = Bill.find(params[:id]) @bill.destroy end <% if @bill.destroyed? %> $("#bill_<%= @bill.id %>").remove(); <% else %> $("#bill_<%= @bill.id %>").prepend("<%= t ('error_while_deleting') %>"); <% end %>
  • 25. Bills @jlucasps Criar action e view edit def edit @bill = Bill.find(params[:id]) end $("#new_bill").html("<%= j(render :partial => 'bills/new', : locals => {:bill => @bill, :user => @bill.user}) %>"); $('html, body').animate({scrollTop: $("#new_bill").offset(). top});
  • 26. Bills @jlucasps Implementar action e view de update def update @bill = Bill.find(params[:id]) flash[:notice] = (@bill.update_attributes(params[:bill]) ? t ('updated_successfully') : t('error_while_updating')) end <% if @bill.valid? %> $("#bills").html("<%= j(render :partial => 'bills/index', :locals => {:bills => @bill.user.bills}) %>"); $("#bills").prepend("<%= j notice %>"); $("#new_bill").html("<%= j(render :partial => 'bills/new', :locals => {:bill => Bill.new, :user => @bill.user} ) %>"); <% else %> $("#new_bill").html("<%= j(render :partial => 'bills/new', :locals => {:bill => @bill, :user => @bill.user}) %>"); <% end %>
  • 28. Desenvolvimento Web com Ruby on Rails João Lucas Pereira de Santana gtalk | linkedin | twitter: jlucasps Obrigado!