Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mini-curso RubyOnRails CESOL

1,031 views

Published on

Mini-curso realizado no CESOL 2009 em Fortaleza na UFC campos do PICI, ministrado por mim Targino Silveira.
Nesse mini-curso viso preparar as pessoas para iniciarem a fazer pequenas aplicações e ao terminarem o mini-curso já sabendo com incluir, editar, excluir, pesquisar registros; alterar templates, trabalhar com migrations e uma outra serie de procedimentos.

Published in: Self Improvement, Technology
  • DOWNLOAD THE BOOK INTO AVAILABLE FORMAT (New Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THE can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THE is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBOOK .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookBOOK, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, EBOOK, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THE Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THE the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THE Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THE BOOK INTO AVAILABLE FORMAT (New Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THE can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THE is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBOOK .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookBOOK, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, EBOOK, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THE Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THE the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THE Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THE BOOK INTO AVAILABLE FORMAT (New Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THE can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THE is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBOOK .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookBOOK, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, EBOOK, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THE Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THE the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THE Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Mini-curso RubyOnRails CESOL

  1. 1. <ul><li>Sobre Ruby: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>Ruby é uma lingugem de programação como as já existentes no mercado, ela é interpletada e cross plataforma, vem sendo muito utilizada para o desenvolvimento web com seu conhecidissimo framework RubyOnRails que faz com que o desenvolvimento se torne extremamente ágil, é uma linguagem de scripts, dinamica porém fortemente tipada, que foi desenvolvida por Yukihiro &quot;Matz&quot; Matsumoto, mas conhecido como&quot;Matz&quot;, e teve sua primeira relese 0.95 anunciada em dezembro de 1995. Segundo seu criado, Ruby foi escrita para programadores e não para máquinas e uma outra declaração do Matz é que ele queria uma linguagem de scripts mais poderosa do que Perl e mais orientada a objetos do que Python, por isso decidiu escrever sua própria linguagem de programação que por sua vez é inspirada em outras linguagens como Perl, Smalltalk, Eiffel, Ada, and Lisp. É completamente orientada a objetos e multiparadigmas de desenvolvimento como funcional, reflectivo e imperativo(programação estruturada). Em sua sintax traz uma similar combinação de Perl e Python. Atualmente o interpletador padrão da linguagem é o MRI(Matz Ruby Interpreter) ou Ruby MRI, que foi escrita em C, e sendo possivel encontrar opções alternativas com YARV, JRuby, Rubinius, IronRuby, e o MacRuby . Sendo que o YARV(Yet Another Ruby VM) é o interpretador padrão da versão 1.9.x que esta em desenvolvimento.
  2. 2. <ul><li>Sobre RubyOnRails: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>Ruby on Rails é um meta-framework gratuito que promete aumentar velocidade e facilidade no desenvolvimento de sites orientados a banco de dados (database-driven web sites), uma vez que é possível criar aplicações com base em estruturas pré-definidas. Frequentemente referenciado como Rails ou RoR, o Ruby on Rails é um projeto de código aberto escrito na linguagem de programação Ruby. As aplicações criadas utilizando o framework Rails são desenvolvidas com base no padrão de projeto MVC (Model-View-Controller). Ruby on Rails foi uma extração de David Heinemeier Hansson de um projeto seu, o gerenciador de projetos Basecamp . Foi lançado a público pela primeira vez em julho de 2004. DRY DRY (Don't Repeat Yourself, Não se repita) é o conceito por trás da técnica de definir nomes, propriedades e códigos em somente um lugar e reaproveitar essas informações em outros. Convention over configuration Na maioria dos casos, usamos convenções no dia-a-dia da programação, em geral para facilitar o entendimento e manutenção por parte de outros desenvolvedores. Sabendo disso, e sabendo que o tempo gasto para configurar XML em alguns frameworks de outras linguagens é extremamente alto, decidiu-se adotar esse conceito.
  3. 3. <ul><li>...continuação </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>Meta-Framework Active Record O Active Record é uma camada de mapeamento objeto-relacional (object-relational mapping layer), responsável pela interoperabilidade entre a aplicação e o banco de dados e pela abstração dos dados. Action Pack Compreende o Action View (geração de visualização de usuário, como HTML, XML, JavaScript, entre outros) e o Action Controller (controle de fluxo de negócio). Action Mailer O Action Mailer é um framework responsável pelo serviço de entrega e até mesmo de recebimento de e-mails. É relativamente pequeno e simples, porém poderoso e capaz de realizar diversas operações apenas com chamadas de entrega de correspondência. Active Support Active Support é uma coleção de várias classes úteis e extensões de bibliotecas padrões, que foram considerados úteis para aplicações em Ruby on Rails.
  4. 4. <ul><li>Cases: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>* BaseCamp * CrunchBase * Github * Hulu * Penny Arcade * Scribd * Spiceworks * Twitter * Urban Dictionary * XING * Yellowpages.com * Slideshare
  5. 5. <ul><li>Instalando o Ruby. </li></ul>sudo apt-get install build-essential sudo apt-get install ruby1.8 ruby1.8-dev rdoc1.8 ri1.8 irb1.8 libopenssl-ruby1.8 wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz tar xvzf rubygems-1.3.5.tgz sudo ruby setup.rb sudo ruby1.8 setup.rb <ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>
  6. 6. <ul><li>Criando link's símbolicos: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby sudo ln -s /usr/bin/gem1.8 /usr/local/bin/gem sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb ruby -v
  7. 7. <ul><li>Instalando o RubyOnRails </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>sudo gem install rails rails -v gedit /home/seu_diretorio_de_usuario/.bashrc PATH=$PATH:/home/seu_diretorio_de_usuario/.gem/ruby/1.8/bin export PATH source /home/seu_diretorio_de_usuario/.bashrc
  8. 8. <ul><li>Criando nossa aplicação: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>rails funcionarios Criação de todos os arquivos da aplicação: create create app/controllers . . create log/test.log
  9. 9. <ul><li>Estrutura da nossa aplicação: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>. |-- app | |-- controllers | |-- helpers | |-- models | `-- views | `-- layouts |-- config | |-- environments | |-- initializers | `-- locales |-- db |-- doc |-- lib | `-- tasks |-- log |-- public | |-- images | |-- javascripts | `-- stylesheets |-- script | `-- performance |-- test | |-- fixtures | |-- functional | |-- integration | |-- performance | `-- unit |-- tmp | |-- cache | |-- pids | |-- sessions | `-- sockets `-- vendor `-- plugins
  10. 10. <ul><li>Os ambientes do arquivo database.yml </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000 production: adapter: sqlite3 database: db/production.sqlite3 pool: 5 timeout: 5000
  11. 11. <ul><li>Criando nossas bases de dados: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>rake db:create rake db:create:all
  12. 12. <ul><li>Executando o WEB Server: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>script/server script/server -p 3001 Trocando o WEBrick pelo mongrel WEBrick 1.3.1 x Mongrel sugo gem install mongrel mongrel_rails -d tail -f log/development.log mongrel_rails mongrel_rails -p 3001 mongrel_rails stop criando nosso promeiro controller
  13. 13. <ul><li>criando nosso promeiro controller e actions: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>script/generate controller home index saudacao app/views/home/index.hmtl.erb: <h1>Esse é o nosso index</h1> <p>Esse é o index da nossa aplicação e aqui vamos ter um link para nosso segunda actions<br> <%= link_to &quot;Vamos para nossa saudação&quot;,:controller => &quot;home&quot;, :action => &quot;saudacao&quot; %> </p> app/views/home/saudacao.hmtl.erb: <h1>Action Saudação</h1> <p>seja bem vindo a saudação do sistema.....</p>
  14. 14. <ul><li>Começando a trabalhar com as rotas: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>Conhecendo o routes.rb config/routes.rb: map.resource :home map.root :controller => &quot;home&quot; rm public/index.html mongrel_rails restart http://localhost:3000
  15. 15. <ul><li>Conhecendo o MVC (Model, View e Controller) </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>|-- app | |-- controllers | |-- helpers | |-- models | `-- views | `-- layouts
  16. 16. <ul><li>criando nosso primeiro CRUD (Create, Read, Update and Delete) </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>script/generate scaffold funcionario nome:string endereco:string bairro:string cidade:string rake db:migrate
  17. 17. <ul><li>Conhecendo nosso arquivo de migration: </li></ul><ul>@voce = </ul>db/migrate/versao_create_funcionarios.rb class CreateFuncionarios < ActiveRecord::Migration def self.up create_table :funcionarios do |t| t.string :nome t.string :endereco t.string :bairro t.string :cidade t.timestamps end end def self.down drop_table :funcionarios end end <ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul>
  18. 18. <ul><li>Criando nosso template: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>app/views/layouts/application.html.erb: <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;> <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;> <head> <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /> <title>Application</title> <link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;application.css&quot; /> </head> <body> <div id=&quot;container&quot;> <div id=&quot;menu&quot;> <%= link_to &quot;Home&quot;, :controller => &quot;home&quot;, :action => &quot;index&quot; %> <%= link_to &quot;Cadastro Funcionario&quot;, :controller => &quot;funcionarios&quot;, :action => &quot;index&quot; %> </div> <div id=&quot;contents&quot;><%= yield %> </div> <div id=&quot;footer&quot;>Todos os direitos reservados.</div> </div> </body> </html>
  19. 19. <ul><li>Executando o cadastro de Funcionário: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>rm app/views/layouts/funcionarios.html.erb abrindo nosso formulario no browser: http://localhost/funcionarios Vamos alterar nosso formulário. Controller e views: app/controllers/funcionarios_controller.rb app/views/funcionarios/new.html.erb app/views/funcionarios/edit.html.erb app/views/funcionarios/show.html.erb app/views/funcionarios/index.html.erb
  20. 20. <ul><li>Criando nosso segundo CRUD: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>script/generate scaffold dependente funcionario_id:integer nome:string rake db:migrate http://localhost:3000/dependentes/index
  21. 21. <ul><li>Criande relacionamentos: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>1º vamos alterar nosso model de funcionario para dizer que um funcionário possui vários dependentes. app/models/funcionario.rb : class Funcionario < ActiveRecord::Base has_many :dependentes end 2º vamos alterar nosso model de dependentes para dizer que cada dependente pertence a um funcionário. app/models/dependente.rb : class Dependente < ActiveRecord::Base belongs_to :funcionario end
  22. 22. <ul><li>Alterando nosso template: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>rm app/views/layouts/dependentes.html.erb app/views/layouts/application.html.erb: <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;> <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;> <head> <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /> <title>Application</title> <%= stylesheet_link_tag 'scaffold' %> </head> <body> <div id=&quot;container&quot;> <div id=&quot;menu&quot;> <%= link_to &quot;Home&quot;, :controller => &quot;home&quot;, :action => &quot;index&quot; %> <%= link_to &quot;Cadastro Funcionários&quot;, :controller => &quot;funcionarios&quot;, :action => &quot;index&quot; %> <%= link_to &quot;Cadastro Dependentes&quot;, :controller => &quot;dependentes&quot;, :action => &quot;index&quot; %> </div> <div id=&quot;contents&quot;> <p style=&quot;color: green&quot;><%= flash[:notice] %></p> <%= yield %> </div> <div id=&quot;footer&quot;>Todos os direitos reservados.</div> </div> </body> </html>
  23. 23. <ul><li>Alterando views para relacionar dependente ao funcionário: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>app/views/dependentes/new.html.erb: Trocar: <%= f.text_field :funcionario_id %> Por: <%= f.select :funcionario_id, options_for_select(Funcionario.all.collect{|d| [d.nome, d.id]} ) %> app/views/dependentes/edit.html.erb: Trocar: <%= f.text_field :funcionario_id %> Por: <%= f.select :funcionario_id, &quot;<option value=#{@dependente.funcionario.id}> #{@dependente.funcionario.nome}</option>&quot; << options_for_select(Funcionario.all.collect{|d| [d.nome, d.id]} ) %>
  24. 24. <ul><li>...Continuação </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>app/views/dependentes/show.html.erb : Trocar: <%=h @dependente.funcionario_id %> Por: <%=h @dependente.funcionario.nome %> app/views/dependentes/index.html.erb: Trocar: <td><%=h dependente.funcionario_id %></td> Por: <td><%=h dependente.funcionario.nome %></td>
  25. 25. <ul><li>Trabalhando com validations padrões do rails: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>app/models/funcionario.rb Inserir: validates_presence_of :nome app/models/funcionario.rb Trocar: validates_presence_of :nome app/models/funcionario.rb Por: validates_presence_of :nome, :message => &quot;O campo deve ser preenchido...&quot; validates_uniqueness_of :nome, :message => &quot;Já cadastrado anteriormente...&quot;
  26. 26. <ul><li>Criando nossas próprias validations: </li></ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>app/models/funcionario.rb Criar o método: def tamanho_nome errors.add(:nome, &quot;Deve ter pelo menos 10 caracteres&quot;) if nome.length < 10 end Inserir a validation: validates_presence_of :nome, :message => &quot;O campo deve ser preenchido...&quot; validates_uniqueness_of :nome, :message => &quot;Já cadastrado anteriormente...&quot; validate :tamanho_nome
  27. 27. <ul>The End...... Obrigado a todos..... Thanks for everyone..... </ul><ul>#{ </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>#{ </ul><ul>} </ul><ul>@voce = </ul>

×