2016-06-03 12 views
0

Wie kann ich Stile für verschiedene Modelle trennen?Paperclip separate Stile

Ich habe meine Photo model, die meine Stile erzeugen

large:'300x300#',huge:'800x800'

ich habe auch zwei Modelle Hexe diese Stile verwenden

Product

und

Post

so will ich

large style nur für Post für Product

und huge style nur

product => has_many :photos 

post => has_one :photo 

photo => belongs_to :post 
     belongs_to :product 
has_attached_file :image, :styles => {large:'300x300#',huge:'800x800'} 

Ist es möglich, benutzen?

+0

Modellcode bereitstellen bitte –

+0

@ МалъСкрылевъ aktualisiert – user

+0

wo ist die Code-Montage Büroklammer? –

Antwort

0

ich Rat Sie Bild von einem Bildmodelltyp separte STI verwenden und Polymorphismus daher hinzufügen imageable_type, imageable_id und type Feld Fotomodell, so:

app/models/photo.rb :

class Photo < AR::Base 
    belongs_to :imageable, polymorphic: true 
end 

app/models/Fotos/large_photo.rb:

class LargePhoto < Photo 
    has_attached_file :image, :styles => { large:'300x300#' } 
end 

app/models/Fotos/huge_photo.rb:

class HugePhoto < Photo 
    has_attached_file :image, :styles => { huge:'800x800' } 
end 

app/models/product.rb:

class Product < AR::Base 
    has_many :large_photos, as: imageable 
end 

app/models/post.rb:

class Post < AR::Base 
    has_one :huge_photo, as: imageable 
end 

ABER für mich, wird besser sein, carrierwave statt paperclip für diesen Fall zu verwenden.