Introdução Ruby On Rails
Upcoming SlideShare
Loading in...5
×
 

Introdução Ruby On Rails

on

  • 563 views

 

Statistics

Views

Total Views
563
Views on SlideShare
561
Embed Views
2

Actions

Likes
1
Downloads
2
Comments
1

2 Embeds 2

http://feeds.feedburner.com 1
http://theoldreader.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Introdução Ruby On Rails Introdução Ruby On Rails Presentation Transcript

    • Ruby On Rails na prática Lukas AlexandreSaturday, January 19, 13
    • O que é? Framework; Open Source; Full stack; Focado em Apps com base de dados; MVC - Model / View / Controller;Saturday, January 19, 13
    • Overview Ruby é uma linguagem de programação; Rails é um framework que provê infraestrutura web; Rails é escrito em Ruby;Saturday, January 19, 13
    • Filosofia do Rails Convention Over Configuration; Don’t Repeat Yourself - DRY; Rails tem opiniões fortes;Saturday, January 19, 13
    • Arquitetura do Rails Aplicações Rails usam Model-View-Controller (MVC); Model - ActiveRecord; View - ActionView; Controller - ActionController;Saturday, January 19, 13
    • E o Ruby? É uma linguagem interpretada; É extremamente orientada a objetos; TUDO é um objeto; Vem de Perl, Smalltalk e Lisp;Saturday, January 19, 13
    • RSS Reader - Criando gem install rails rails new rss_reader cd rss_reader rails server http://localhost:3000 Welcome Aboard!!!Saturday, January 19, 13
    • Estrutura de diretórios /app /controllers /helpers /models /views/nome_do_controllerSaturday, January 19, 13
    • Estrutura de diretórios /config /log /db /public /doc /test /lib /tmpSaturday, January 19, 13
    • Modos de execução Desenvolvimento (development) Teste (test) Produção (production)Saturday, January 19, 13
    • Welcome Aboard - E agora? No terminal: rails generate scaffold feed name:string rake db:migrate rm public/index.html routes.rb root :to => feeds#indexSaturday, January 19, 13
    • Res...what?? Restful! Index - Listagem dos recursos Show - Detalhes do recurso New - Preenchendo um novo recurso Create - Criando um novo recurso Edit - Preenchendo os dados de um recurso existente Update - Atualizando um recurso Destroy - Removendo um recursoSaturday, January 19, 13
    • Verbalizando a Web (http verbs) Get Post Put DeleteSaturday, January 19, 13
    • Rotas...hã? http://localhost:3000/feeds/hello_world http://localhost:3000 - endereco e porta do servidor feeds - nome do controlador hello_world - nome da ação (método no controller)Saturday, January 19, 13
    • Armazenando os dados config/database.yml development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000Saturday, January 19, 13
    • Models, o que são e para onde vão? class Feed < ActiveRecord::Base attr_accessible :name end Negociar; Representar;Saturday, January 19, 13
    • Migrations Ficam em db/migrations; Versionamento do banco; Devem ser criadas a cada alteração da estrutura de dados; Esqueleto do banco (schema.rb); Reversíveis;Saturday, January 19, 13
    • Como se parecem: class CreateFeeds < ActiveRecord::Migration def change create_table :feeds do |t| t.string :name t.timestamps end end endSaturday, January 19, 13
    • E as Views?! app/views/feeds/index.html.erb <% @feeds.each do |feed| %> <tr> <td><%= feed.name %></td> <td><%= link_to Show, feed %></td> <td><%= link_to Edit, edit_feed_path(feed) %></td> <td><%= link_to Destroy, feed, method: :delete, data: { confirm: Are you sure? } %></td> </tr> <% end %>Saturday, January 19, 13
    • Convention over Configuration O model de Feed “automagicamente” procura por uma tabela em seu plural; O controller “automagicamente” acha e renderiza as views corretas usando seu nome e ação executada (views/feeds/index.html);Saturday, January 19, 13
    • Feed sem nome?? Validações nele! validates_presence_of validates_length_of validates_acceptance_of validates_uniqueness_of validates_format_of validates_numericality_of validates_inclusion_in validates_exclusion_of Entre outros...Saturday, January 19, 13
    • E como ficaria? class Feed < ActiveRecord::Base attr_accessible :name validates_presence_of :name endSaturday, January 19, 13
    • E os itens do feed? rails generate scaffold feed_item feed:references title:string content:text rake db:migrateSaturday, January 19, 13
    • Associations...a rede social dos models has_one belongs_to has_many has_and_belongs_to_many has_many :model1, :through => :model2 has_one :model1, :through => :model2Saturday, January 19, 13
    • E no nosso caso? class FeedItem < ActiveRecord::Base belongs_to :feed attr_accessible :content, :title end class Feed < ActiveRecord::Base has_many :feed_items ... endSaturday, January 19, 13
    • Mostrando itens por feed app/views/feeds/show.html.erb <section> <% @feed.feed_items.each do |feed_item| %> <article> <header> <h1><%= feed_item.title %></h1> </header> <p> <%= feed_item.content %> </p> </article> <% end -%> </section>Saturday, January 19, 13
    • Mergulhando no ActiveRecord Querys SQL complexas; Join Left Join Agrupando; Ordenando;Saturday, January 19, 13
    • Porque Rails? Resolve 90% dos problemas; Foco no negócio; Ecossistema gigantesco; Comunidade receptiva; Ready to go;Saturday, January 19, 13
    • Porque Ruby? Intuitiva; POUCO verbosa; Extremamente dinâmica; Gostosa de escrever;Saturday, January 19, 13
    • Ferramentas de trabalho Sublime Text 2 / VIM; Total Terminal; Patterns (Regex); Kindle (armado até os dentes!);Saturday, January 19, 13
    • Contato pessoal: lukasalexandre@me.com profissional: lukas@codelogic.me http://github.com/lukasalexandreSaturday, January 19, 13
    • Perguntas?Saturday, January 19, 13
    • Obrigado!Saturday, January 19, 13
    • Referências guides.rubyonrails.org Agile Web Development with RailsSaturday, January 19, 13