Created
June 29, 2010 20:16
-
-
Save bamnet/457747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% @content.medias.build({:key=>"original"}) %> | |
<%= form_for(@content, :html => { :multipart => true }) do |f| %> | |
<div class="field"> | |
<%= f.fields_for :medias do |media| %> | |
<%= media.file_field :file %> | |
<%= media.hidden_field :key %> | |
<% end %> | |
</div> | |
<div class="actions"> | |
<%= f.submit %> | |
</div> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for(@content) do |f| %> | |
<div class="field"> | |
<%= f.label :data %><br /> | |
<%= f.text_area :data %> | |
</div> | |
<div class="actions"> | |
<%= f.submit %> | |
</div> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Content < ActiveRecord::Base | |
belongs_to :user | |
belongs_to :kind | |
has_many :submissions, :dependent => :destroy | |
has_many :feeds, :through => :submissions | |
has_many :medias, :as => :attachable | |
accepts_nested_attributes_for :medias | |
accepts_nested_attributes_for :submissions | |
#Validations | |
validates :name, :presence => true | |
validates :kind, :presence => true, :associated => true | |
validates :user, :presence => true, :associated => true | |
validates :duration, :numericality => { :greater_than => 0 } | |
#Easily query for active, expired, or future content | |
scope :expired, where("end_time < :now", {:now => Time.now}) | |
scope :future, where("start_time > :now", {:now => Time.now}) | |
scope :active, where("(start_time IS NULL OR start_time < :now) AND (end_time IS NULL OR end_time > :now)", {:now => Time.now}) | |
#Scoped relations for feed approval states | |
has_many :approved_feeds, :through => :submissions, :source => :feed, :conditions => {"submissions.moderation_flag" => true} | |
has_many :pending_feeds, :through => :submissions, :source => :feed, :conditions => "submissions.moderation_flag IS NULL" | |
has_many :denied_feeds, :through => :submissions, :source => :feed, :conditions => {"submissions.moderation_flag" => false} | |
# Determine if content is active based on its start and end times. | |
# Content is active if two conditions are met: | |
# 1. Start date is before now, or nil. | |
# 2. End date is after now, or nil. | |
def is_active? | |
(start_time.nil? || start_time < Time.now) && (end_time.nil? || end_time > Time.now) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Graphic < Content | |
#Validations | |
validates :duration, :numericality => { :greater_than => 0 } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% content_for :left_sidebar do %> | |
<ul> | |
<% Content.subclasses.each do |subclass| %> | |
<li><%= link_to subclass.model_name.human, new_content_path(:type=>subclass.model_name.singular) %></li> | |
<% end %> | |
</ul> | |
<% end %> | |
<%= render 'contents/forms/#{type_will_go_here}' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ticker < Content | |
#Validations | |
validates :duration, :numericality => { :greater_than => 0 } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment