mam jeszcze jedno pytanie
można zrobić coś z takim czymś
[code=ruby]class App < ActiveRecord::Base
attr_accessible :active, :name, :page_id, :user_id, :app_type, :block, :html
validates :name, :length => { :in => 3…40 }
validates_presence_of :page_id
has_one :applications_typ, :primary_key=>:app_type, :foreign_key=>:id
has_one :fanpage, :primary_key=>:page_id, :foreign_key=>:id
has_one :app_config, :dependent => :destroy
has_many :app_progress, :dependent => :destroy
has_one :app_detal, :dependent => :destroy, :primary_key=>:id, :foreign_key=>:app_id
has_many :app_look, :dependent => :destroy
has_many :app_wall, :dependent => :destroy
has_many :app_obligation_like_pages, :dependent => :destroy
has_many :app_puzzle_imagess, :dependent => :destroy
has_many :app_puzzle_resultss, :dependent => :destroy
has_many :app_text, :dependent => :destroy
has_many :invite, :dependent => :destroy
has_many :app_text_resultss, :dependent => :destroy
has_many :app_image_resultss, :dependent => :destroy
has_many :app_image, :dependent => :destroy
has_many :app_cards, :dependent => :destroy
has_many :app_cards_resultss, :dependent => :destroy
has_many :app_users, :dependent => :destroy
has_many :view, :dependent => :destroy
has_many :app_ranking, :dependent => :destroy
has_many :app_draw, :dependent => :destroy
has_many :app_obligation_like_page, :dependent => :destroy
has_one :client, :primary_key=>:user_id, :foreign_key=>:id
has_one :app_active, :dependent => :destroy, :primary_key=>:id, :foreign_key=>:app_id
after_create :after_create
def after_create
#add progres
AppProgres.insert_progres self.id, ‘config_step_1’, 10
#add app config
app_config = AppConfig.AppDetal.AppLook.AppWall.AppActive.new :app_id => self.id
app_config.save
#add app detal
app_config = AppDetal.new :app_id => self.id
app_config.save
#add app look
app_look = AppLook.new :app_id => self.id
app_look.save
#add app wall
app_wall = AppWall.new :app_id => self.id
app_wall.save
#add app active
app_active = AppActive.new :app_id => self.id
app_active.save
end
def self.list(page_id)
App.find(
:all,
:joins => [:app_active,:app_detal],
:select => ‘apps.app_type as app_type, app_detals.html as html, apps.id as id, apps.name as name, app_actives.active as active,app_detals.date_start as date_start, app_detals.date_see as date_see,app_detals.time_start as time_start’,
:conditions => [“block = ‘0’ and active = ‘1’ and page_id = '”+page_id.to_s+"’ and CONCAT(date_start,’ ',time_start) <= ‘"+Time.now.strftime("%Y-%m-%d %H:%M")+"’ and date_see >= ‘"+Time.now.strftime("%Y-%m-%d")+"’ "]
)
end
end[/code]