Skip to content

Instantly share code, notes, and snippets.

@thedelchop
Created August 30, 2011 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedelchop/1182190 to your computer and use it in GitHub Desktop.
Save thedelchop/1182190 to your computer and use it in GitHub Desktop.
Unorganized code
class News < ActiveRecord::Base
acts_as_commentable
cattr_reader :per_page
@@per_page = 7
belongs_to :user
has_many :posts, :as => :posting, :dependent => :destroy
has_attached_file :image,
:styles => {
:large => "400x400>",
:large_headline => "400x225#",
:medium_headline => "250x195#",
:thumb => "50x50#"
},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension"
default_scope order("created_at desc")
scope :with_images, where("image_file_name IS NOT NULL")
has_many :_endorsements, :as => :item, :class_name => 'Endorsement'
def body_html
RedCloth.new(self.body).to_html.gsub(/<\/?del>/,' - ')
end
def followers
self.user.followers
end
def commenters
self.comments.map {|comment| comment.user }.uniq #=> ["a!", "b!", "c!", "d!"]
end
# emits_pfeeds :on => [:create] , :for => [ :participant_only ] # also available – :itself, :all_in_its_class
# receives_pfeed
validates_presence_of :title, :body, :summary
validates_length_of :summary, :maximum => 200
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment