Rails e suas Gems

990 views
935 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
990
On SlideShare
0
From Embeds
0
Number of Embeds
239
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Rails e suas Gems

  1. 1. Rails e suas Gems @rr_martins Rodrigo Martins [email_address]
  2. 2. Gems? É bom assim por dentro?
  3. 3. Gems? <ul><li>http://docs.rubygems.org/ </li></ul><ul><li>Gerenciador de pacotes do Ruby. </li></ul>Uiiii... Uma Joia... :D
  4. 4. Um pouco de Ruby! (String) <ul><li>>> string = &quot; liberdade Interativa! eu Fui!&quot; </li></ul><ul><li>=> &quot; liberdade Interativa! eu Fui!&quot; </li></ul><ul><li>>> def chamada(evento=&quot;LI&quot;) </li></ul><ul><li>>> puts evento.to_s+&quot; Eu fui!&quot; </li></ul><ul><li>>> end </li></ul><ul><li>>> chamada(&quot;Liberdade Interativa&quot;) </li></ul><ul><li>=> Liberdade Interativa Eu fui! </li></ul><ul><li>>> chamada </li></ul><ul><li>=> LI Eu fui! </li></ul>
  5. 5. Um pouco de Ruby! (Array) <ul><li>>> evento = Array.new </li></ul><ul><li>>> evento << &quot;LI&quot; </li></ul><ul><li>=> [&quot;LI&quot;] </li></ul><ul><li>>> evento << &quot;Liberdade Interativa&quot; </li></ul><ul><li>=> [&quot;LI&quot;, &quot;Liberdade Interativa&quot;] </li></ul><ul><li>>> evento << &quot;RockOnRails&quot; </li></ul><ul><li>=> [&quot;LI&quot;, &quot;Liberdade Interativa&quot;, &quot;RockOnRails&quot;] </li></ul>
  6. 6. Um pouco de Ruby! (Array) <ul><li>>> def chamada(evento) </li></ul><ul><li>>> evento.each do |even| </li></ul><ul><li>>> puts even.to_s+&quot; Eu Fui! :D&quot; </li></ul><ul><li>>> end </li></ul><ul><li>>> end </li></ul><ul><li>>> chamada(evento) </li></ul><ul><li>=> LI Eu Fui! :D </li></ul><ul><li>=> Liberdade Interativa Eu Fui! :D </li></ul><ul><li>=> RockOnRails Eu Fui! :D </li></ul>
  7. 7. Já posso usar as Gems? Calma! Vamos com calma, as Gems precisam do Rails!
  8. 8. Projeto Blog!
  9. 9. Gems Apresentadas! <ul><li>-> Paperclip->github.com/thoughtbot/paperclip </li></ul><ul><li>Sugestão: Rodrigo Mendonça (rails-br) </li></ul><ul><li>-> Devise -> github.com/plataformatec/devise </li></ul><ul><li>Sugestão: Celso Dantas (rails-br) </li></ul><ul><li>-> Twitter -> github.com/jnunemaker/twitter </li></ul>
  10. 10. Projeto Rails criado.. <ul><li>rails new <projeto> </li></ul>
  11. 11. Gems Apresentadas! <ul><li>-> Paperclip </li></ul><ul><li>-> github.com/thoughtbot/paperclip </li></ul><ul><li>Sugestão: Rodrigo Mendonça (rails-br) </li></ul><ul><li>-> Devise -> github.com/plataformatec/devise </li></ul><ul><li>Sugestão: Celso Dantas (rails-br) </li></ul><ul><li>-> Twitter -> github.com/jnunemaker/twitter </li></ul>
  12. 12. PaperClip <ul><li>No GemFile: </li></ul><ul><li>gem &quot;paperclip&quot;, &quot;~> 2.4&quot; </li></ul><ul><li>No Model: (Post) </li></ul><ul><li>has_attached_file :image, :styles => { :medium => &quot;300x300>&quot;, :thumb => &quot;100x100>&quot; } </li></ul>
  13. 13. PaperClip <ul><li>Migrate : </li></ul><ul><li>class AddImageToPost < ActiveRecord::Migration </li></ul><ul><li>def self.up </li></ul><ul><li>add_column :posts, :image_file_name, :string </li></ul><ul><li>add_column :posts, :image_content_type, :string </li></ul><ul><li>add_column :posts, :image_file_size, :integer </li></ul><ul><li>add_column :posts, :image_updated_at, :datetime </li></ul><ul><li>end </li></ul><ul><li>def self.down </li></ul><ul><li>remove_column :posts, :image_updated_at </li></ul><ul><li>remove_column :posts, :image_file_size </li></ul><ul><li>remove_column :posts, :image_content_type </li></ul><ul><li>remove_column :posts, :image_file_name </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  14. 14. PaperClip <ul><li><%= form_for :post, :url => posts_path, : </li></ul><ul><ul><li>html => { :class => :form, :multipart => true } do |f| -%> </li></ul></ul><ul><li><div class=&quot;field&quot;> </li></ul><ul><li><strong><%= f.label :data %></strong> </li></ul><ul><li><%= f.hidden_field :data, :value => Time.now %> </li></ul><ul><li><%= f.label Time.now.to_date %> </li></ul><ul><li></div> </li></ul><ul><li><div class=&quot;field&quot;> </li></ul><ul><li><%= f.label :titulo %><br /> </li></ul><ul><li><%= f.text_field :titulo %> </li></ul><ul><li></div> </li></ul><ul><li><div class=&quot;field&quot;> </li></ul><ul><li><%= f.label :chamada %><br /> </li></ul><ul><li><%= f.text_field :chamada %> </li></ul><ul><li></div> </li></ul>
  15. 15. PaperClip <ul><li><div class=&quot;field&quot;> </li></ul><ul><li><%= f.label :texto %><br /> </li></ul><ul><li><%= f.text_area :texto %> </li></ul><ul><li></div> </li></ul><ul><li><div class=&quot;field&quot;> </li></ul><ul><li><%= f.label &quot;Imagem&quot; %> </li></ul><ul><li><%= f.file_field :image %> </li></ul><ul><li></div> </li></ul><ul><li><div class=&quot;actions&quot;> </li></ul><ul><li><%= f.submit %> </li></ul><ul><li></div> </li></ul><ul><li><% end -%> </li></ul>
  16. 16. PaperClip <ul><li>View Show: </li></ul><ul><li><%= image_tag @post.image.url if !@post.image_file_name.nil? %> </li></ul><ul><li><%= image_tag @post.image.url(:medium) if !@post.image_file_name.nil? %> </li></ul><ul><li><%= image_tag @post.image.url(:thumb) if !@post.image_file_name.nil? %> </li></ul>
  17. 17. PaperClip
  18. 18. Gems Apresentadas! <ul><li>-> Paperclip->github.com/thoughtbot/paperclip </li></ul><ul><li>Sugestão: Rodrigo Mendonça (rails-br) </li></ul><ul><li>-> Devise -> github.com/plataformatec/devise </li></ul><ul><li>Sugestão: Celso Dantas (rails-br) </li></ul><ul><li>-> Twitter -> github.com/jnunemaker/twitter </li></ul>
  19. 19. Devise
  20. 20. Devise <ul><li>Gemfile: </li></ul><ul><li>gem “devise” </li></ul><ul><li>Iniciando o Devise: </li></ul><ul><li>rails generate devise:install </li></ul><ul><li>Configurando um model: </li></ul><ul><li>rails generate devise usuario </li></ul>
  21. 21. Devise
  22. 22. Devise <ul><li>Rodando Migrate: </li></ul>
  23. 23. Devise <ul><li>Autenticando Controller: </li></ul><ul><li>before_filter :authenticate_user! </li></ul><ul><li>before_filter :authenticate_user!, </li></ul><ul><li>:except => [:index, :show, :create] </li></ul>
  24. 24. Gems Apresentadas! <ul><li>-> Paperclip->github.com/thoughtbot/paperclip </li></ul><ul><li>Sugestão: Rodrigo Mendonça (rails-br) </li></ul><ul><li>-> Devise -> github.com/plataformatec/devise </li></ul><ul><li>Sugestão: Celso Dantas (rails-br) </li></ul><ul><li>-> Twitter -> github.com/jnunemaker/twitter </li></ul>
  25. 25. Twitter
  26. 26. Twitter <ul><li>GemFile: </li></ul><ul><li>gem 'twitter' </li></ul>
  27. 27. Twitter <ul><li><table border=&quot;0&quot;> </li></ul><ul><li><tr> </li></ul><ul><li><td><%= image_tag Twitter.profile_image(&quot;rr_martins&quot;, :size => 'bigger') %></td> </li></ul><ul><li><td><%= Twitter.user('rr_martins').location %> </li></ul><ul><li><br> <%= Twitter.user('rr_martins').description %> </li></ul><ul><li></td> </li></ul>
  28. 28. Twitter <ul><li></tr> </li></ul><ul><li><% Twitter.user_timeline(&quot;rr_martins&quot;,{:count=>5}).each do |twit| %> </li></ul><ul><li><tr> </li></ul><ul><li><td colspan=&quot;2&quot;><%= twit.text %></td> </li></ul><ul><li></tr> </li></ul><ul><li><% end %> </li></ul><ul><li></table> </li></ul>
  29. 29. Fontes <ul><li>http://github.com </li></ul><ul><li>https://www.ruby-toolbox.com </li></ul><ul><li>http://rubygems.org/ </li></ul><ul><li>Em breve: </li></ul><ul><li>http://rrmartins.com </li></ul><ul><li>https://github.com/rrmartins/blog </li></ul>
  30. 30. Duvidas? @rr_martins Rodrigo Martins [email_address]
  31. 31. Obrigado! @rr_martins Rodrigo Martins [email_address]

×