Created
August 7, 2011 07:52
-
-
Save basti/1130173 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
class News < ActiveRecord::Base | |
has_many :quotes, :autosave=>true, :dependent=>:destroy, :order => "position" | |
MAX_QUOTES = 3 | |
before_save :remove_excess_quotes | |
protected | |
def remove_excess_quotes | |
if self.quotes.count > MAX_QUOTES | |
self.quotes.destroy_all ["position > ?", MAX_QUOTES] # nisam siguran da li ["",...] sintaksa radi za destroy_all - trebalo bi, ako ne radi samo napravi obican string | |
end | |
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 Quote < ActiveRecord::Base | |
belongs_to :news | |
# https://github.com/swanandp/acts_as_list | |
# pogledaj i sam source da vidis koje sve metode ima: | |
# https://github.com/swanandp/acts_as_list/blob/master/lib/acts_as_list/active_record/acts/list.rb | |
acts_as_list :scope => :news | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment