Hi, My question is a bit of wonder and a bit of enlightment. I have two models, Channel and ChannelItem, the second is a list of Events, ordered by position (because I''m using acts_as_list). Later I use a method in Channel to recalculate the hour when that show come online, based on the duration of it and doing math based on the previous one duration and start time, starting from 0:00. So, with this info (channel_items): id | channel_id | event_id | position | starttime 1 | 1 | 3 | 1 | 2 | 1 | 5 | 2 | 3 | 1 | 2 | 3 | 4 | 1 | 1 | 4 | [...] After processing it with recalculate_hours get this (all starting 00:00): id | channel_id | event_id | position | starttime 1 | 1 | 3 | 1 | 00:00 (event.duration = 1:00) 2 | 1 | 5 | 2 | 01:00 (event.duration = 0:30) 3 | 1 | 2 | 3 | 01:30 (event.duration = 0:45) 4 | 1 | 1 | 4 | 02:15 (event.duration = 0:30) [...] Ok, Every time I rearrange the schedule (the channel information), need to call recalculate method, which is a bit expensive to do for 24hs schedules How could I implement this methods as "acts" so remove the dependency on acts_as_list and use my own? also if I could get "next available position" as time instead of integer? Hope the question is clear, and hope someone could enlight me in the right direction. Regards, Luis -- Posted via http://www.ruby-forum.com/.
Luis Lavena wrote:> Hi,...> id | channel_id | event_id | position | starttime > 1 | 1 | 3 | 1 | 00:00 (event.duration = 1:00) > 2 | 1 | 5 | 2 | 01:00 (event.duration = 0:30) > 3 | 1 | 2 | 3 | 01:30 (event.duration = 0:45) > 4 | 1 | 1 | 4 | 02:15 (event.duration = 0:30) > [...] > > Ok, Every time I rearrange the schedule (the channel information), need > to call recalculate method, which is a bit expensive to do for 24hs > schedules > > How could I implement this methods as "acts" so remove the dependency on > acts_as_list and use my own? also if I could get "next available > position" as time instead of integer?I''d try to have the starttime column be computed If your db doesn''t handle time computations, I''d change your column type to BIGINT and store the time offest in seconds (formatting into minutes:seconds can be done in an helper). Supposing you have a column duration and you use Postgres: select id,channel_id,duration, COALESCE((select sum(duration) from test as test2 where test2.position<test1.position), ''0:00:00'') as starttime from test as test1 order by position; will return a computed starttime. Then you may build a view in Postgres to make your virtual column starttime visible by AR, or use a custom find_by_sql. If you want to make an acts_as, see on wiki.rubyonrails.org, there''s a tutorial to write an acts_as. Base thing is to write a module that will be evaluated in ActiveRecord and change the behaviour as you wish. -- Jean-Christophe Michel