开发者

How to make a limit points by month in Rails?

开发者 https://www.devze.com 2023-03-05 05:37 出处:网络
In my new rails project,I want to limit the user\'s post number by something like point.At the begining of every month,every user was given limited points.When user use up their points,they can\'t do

In my new rails project,I want to limit the user's post number by something like point.At the begining of every month,every user was given limited points.When user use up their points,they can't do any thing.

My question is,how to give user this points at the begining of every 开发者_运维百科month automatically in Rails?How to design the model and controller?

Thank you.


I think you should use something like whenever to schedule your tasks. Here is 'monthly jobs syntax question' from whenever mailing list. In general you will have something like:

# shedule.rb
every 1.month, :at => "beginning of the month at 3am" do
  runner "User.set_points" # or rake "task:for:user:set_poins" if you have rake task for this
end

# user.rb
def self.set_points
  User.all.each{|u| u.update_attribute(:points, some_function_to_calculate_points(u)}
end

I hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消