【发布时间】:2011-07-24 23:16:02
【问题描述】:
我正在尝试将用户的帖子限制为每天一次,我正在考虑检查 Time.now - last_post_time 是否为
我想做的是只允许一个月内每天发一个帖子,所以如果用户在 3 月 28 日发帖,他在 29 日之前不能再次发帖。但如果他在 3 月 28 日晚上 10 点发帖,他可以在 3 月 29 日凌晨 12:01 再次发帖。
我该怎么做?
编辑:
这是我的posts_controller,我可以就如何重构它获得一些帮助吗?
def create
@post = current_user.posts.build(params[:supportpost])
if @post.save
flash[:success] = "Your post was created!"
redirect_to root_path
else
@feed_items = []
render 'pages/home'
end
end
我正在尝试这样的事情,但它肯定是错误的:
def create
post = @user.posts.find(:first, :conditions => ["STRFTIME('%d', created_at) = ?", Date.today.day])
if post
@post = current_user.posts.build(params[:supportpost])
if @post.save
flash[:success] = "Your post was created!"
redirect_to root_path
else
@feed_items = []
render 'pages/home'
end
end
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 validation time