Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow content to control what field and screens it is displayed in.

Content classes now include a can_display_in? method which contains the logic we use to see if a piece of content should be rendered in a specific <screen, field>.  To provide parity with the default behavior, we simply make sure that the Field.Kind == Content.Kind.
  • Loading branch information...
commit 2af444698e1ec5b790d706c555311bed73df31e4 1 parent 174d161
@bamnet bamnet authored
Showing with 10 additions and 1 deletion.
  1. +7 −0 app/models/content.rb
  2. +3 −1 app/models/subscription.rb
View
7 app/models/content.rb
@@ -222,4 +222,11 @@ def self.filter_all_content(params)
filtered_contents
end
+ # Determine if a piece of content should be displayed based on screen and field.
+ # By default content can be rendered in any Field which has the same Kind as the Content.
+ # This can be overridden by different content types which can be displayed in different
+ # fields or based on some dynamic criteria implemented in each Content subclass.
+ def can_display_in?(screen, field)
+ return self.kind == field.kind
+ end
end
View
4 app/models/subscription.rb
@@ -32,6 +32,8 @@ def weight_name
# Get an array of all the approved active content to be shown in a screen's field.
def contents
- self.feed.approved_contents.active.where(:kind_id => self.field.kind.id)
+ contents = self.feed.approved_contents.active.all
+ contents.reject!{|c| !c.can_display_in?(self.screen, self.field)}
+ return contents
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.