Act as
Upcoming SlideShare
Loading in...5
×
 

Act as

on

  • 2,241 views

Uma breve explicação do funcionamento do acts_as

Uma breve explicação do funcionamento do acts_as

Statistics

Views

Total Views
2,241
Views on SlideShare
796
Embed Views
1,445

Actions

Likes
0
Downloads
1
Comments
0

2 Embeds 1,445

http://blog.giran.com.br 1443
url_unknown 2

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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

Act as Act as Presentation Transcript

  • 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_reviewable has_many :reviews , :as => :reviewable , :dependent => :destroy include InstanceMethods end module InstanceMethods def reviewable? true end end end ActiveRecord::Base.extend Reviewable
  • class Produto < ActiveRecord::Base is_reviewable end class Categoria < ActiveRecord::Base is_reviewable end class Artigo < ActiveRecord::Base is_reviewable end
  • 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.reviews.create(review_text: &quot;test&quot;) => #<Review id: 1, reviewable_type: &quot;Product&quot;, reviewable_id: 101 ....> product.reviews.size => 1
  • BLOCOS
  • Dúvidas?