0
ACTS AS André Tagliati @tagliati http://www.tagliati.com.br [email_address]
Tagliati E @makotovh papagaio de pirata
http://www.cowboycoded.com/tag/acts_as/   http://www.flickr.com/photos/loop_oh/3338084111/
DRY DONT REPEAT YOURSELF DRY http://www.flickr.com/photos/vorty/850290006/
Review Ou Acts as Reviewable REVIEWABLE
Hands On Vamos ver como é isso. HANDS ON  http://www.flickr.com/photos/jurvetson/489257240/
rails g model  review review_text:text t.references  :reviewable ,  :polymorphic  =>  true
Ali! No teto!  Polymorphic!!!! Me enganei.  É só um PomboRanger.
class  Review < ActiveRecord::Base belongs_to  :reviewable ,  :polymorphic => true end module  Reviewable def  is_reviewab...
class  Produto < ActiveRecord::Base is_reviewable end class  Categoria < ActiveRecord::Base is_reviewable end class  Artig...
http://www.flickr.com/photos/80835774@N00/5442336248/ hehaEHAEHaeHe haHeAHeAHeAHe HAEhae Assim fica fácil!
product = Product.new => # product.reviewable? => true product.reviews => []  #nenhum review ainda product.save product.re...
BLOCOS
Dúvidas?
Upcoming SlideShare
Loading in...5
×

Act as

2,152

Published on

Uma breve explicação do funcionamento do acts_as

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
2,152
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Apresentação tomando como base explicação em artigo de cowboycoded
  • Criar um &apos;plugin&apos; que permita fazer reviews de um produto ou qualquer outra coisa
  • Polymorphic relationships allow you to have a single model that can be associated to an arbitrary number of other model types. Example For instance, let&apos;s say you have a contacts database utilizing two models, Person and Company. Both people and companies have addresses that you want to store in the database, and you want to be able to query against all addresses at once (say for a location-based search). Polymorphic associations make this easy in Rails. Let&apos;s assume that you already have your Person and Company models created and are just creating your Address model. When you create your migration you will denote the polymorphic relationship using references: http://wiki.rubyonrails.org/howtos/db-relationships/polymorphic
  • Transcript of "Act as"

    1. 1. ACTS AS André Tagliati @tagliati http://www.tagliati.com.br [email_address]
    2. 2. Tagliati E @makotovh papagaio de pirata
    3. 3. http://www.cowboycoded.com/tag/acts_as/ http://www.flickr.com/photos/loop_oh/3338084111/
    4. 4. DRY DONT REPEAT YOURSELF DRY http://www.flickr.com/photos/vorty/850290006/
    5. 5. Review Ou Acts as Reviewable REVIEWABLE
    6. 6. Hands On Vamos ver como é isso. HANDS ON http://www.flickr.com/photos/jurvetson/489257240/
    7. 7. rails g model review review_text:text t.references :reviewable , :polymorphic => true
    8. 8. Ali! No teto! Polymorphic!!!! Me enganei. É só um PomboRanger.
    9. 9. class Review < ActiveRecord::Base belongs_to :reviewable , :polymorphic => true end module Reviewable def is_reviewable has_many :reviews , :as => :reviewable , :dependent => :destroy include InstanceMethods end module InstanceMethods def reviewable? true end end end ActiveRecord::Base.extend Reviewable
    10. 10. class Produto < ActiveRecord::Base is_reviewable end class Categoria < ActiveRecord::Base is_reviewable end class Artigo < ActiveRecord::Base is_reviewable end
    11. 11. http://www.flickr.com/photos/80835774@N00/5442336248/ hehaEHAEHaeHe haHeAHeAHeAHe HAEhae Assim fica fácil!
    12. 12. product = Product.new => # product.reviewable? => true product.reviews => [] #nenhum review ainda product.save product.reviews.create(review_text: &quot;test&quot;) => #<Review id: 1, reviewable_type: &quot;Product&quot;, reviewable_id: 101 ....> product.reviews.size => 1
    13. 13. BLOCOS
    14. 14. Dúvidas?
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×