先是
before_filter :authorize_post!, only: [:new, :create]
然后是
protected
def authorize_post!
if @forum.id < 6
redirect_to posts_url, alert: "此板块不允许发帖"
elsif DateTime.parse(Time.now.to_s) - DateTime.parse(current_user.created_at.to_s) < 7
unless Post.where("author_id = #{current_user.id} AND to_days(created_at) = to_days(now()) ").count < 5
redirect_to posts_url, alert: "未满一周用户每天只能发5篇帖子"
end
end
end
我自己测试都没有问题,符合条件得都 redirect_to 我定义得地址了,但是为什么还是有人可以无穷无尽的发?