Your SlideShare is downloading. ×
0
Act as
Act as
Act as
Act as
Act as
Act as
Act as
Act as
Act as
Act as
Act as
Act as
Act as
Act as
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Act as

2,146

Published on

Uma breve explicação do funcionamento do acts_as

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Apresentação tomando como base explicação em artigo de cowboycoded
  • Criar um 'plugin' 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'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'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

    • 1. ACTS AS André Tagliati @tagliati http://www.tagliati.com.br [email_address]
    • 2. Tagliati E @makotovh papagaio de pirata
    • 3. http://www.cowboycoded.com/tag/acts_as/ http://www.flickr.com/photos/loop_oh/3338084111/
    • 4. DRY DONT REPEAT YOURSELF DRY http://www.flickr.com/photos/vorty/850290006/
    • 5. Review Ou Acts as Reviewable REVIEWABLE
    • 6. Hands On Vamos ver como é isso. HANDS ON http://www.flickr.com/photos/jurvetson/489257240/
    • 7. rails g model review review_text:text t.references :reviewable , :polymorphic => true
    • 8. Ali! No teto! Polymorphic!!!! Me enganei. É só um PomboRanger.
    • 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. class Produto < ActiveRecord::Base is_reviewable end class Categoria < ActiveRecord::Base is_reviewable end class Artigo < ActiveRecord::Base is_reviewable end
    • 11. http://www.flickr.com/photos/80835774@N00/5442336248/ hehaEHAEHaeHe haHeAHeAHeAHe HAEhae Assim fica fácil!
    • 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. BLOCOS
    • 14. Dúvidas?

    ×