ruby - Automatically create instance of a model every day with rails -


i writing app 2 models, user , daily. each user has_many dailies. trying create daily report each user every day @ midnight. how do in rails? in backbone, find time between , midnight, set timeout amount of time, , create new model, , call function recursively. looked @ rails: reset model attribute @ specific time each day , saw suggestion use whenever , cron, wasn't sure if there better way accomplish trying do.

a temporary solution came create new daily when user visits home page if current user doesn't have daily today's date. has problem of creating report day if user visits homepage on day. if user navigates around homepage, report won't created, , think it's intrusive solution put check in every action. there way in rails automate task?

edit: idea had put after_create daily class, , use same solution backbone solution. optimal way accomplish this?

you should check out gem whenever.

it allows define tasks in readable dsl in config/schedule.rb file this: (examples taken gem readme):

every 3.hours   runner "mymodel.some_process"   rake "my:rake:task"   command "/usr/bin/my_great_command" end  every 1.day, :at => '4:30 am'   runner "mymodel.task_to_run_at_four_thirty_in_the_morning" end  every :hour # many shortcuts available: :hour, :day, :month, :year, :reboot   runner "somemodel.ladeeda" end  every :sunday, :at => '12pm' # use day of week or :weekend, :weekday   runner "task.do_something_great" end  every '0 0 27-31 * *'   command "echo 'you can use raw cron syntax too'" end  # run task on servers :app role in capistrano # see capistrano roles section below every :day, :at => '12:20am', :roles => [:app]   rake "app_server:task" end 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -