I try to limit the number of user messages once a day, I was thinking about checking if Time.now is last_post_time <(second time a day), but then it will force a 24-hour period between each message.
What I would like to do is just one post per day per month, so if the user posts on March 28th, he will not be able to post the message until the 29th. But if he leaves at 22:00 on March 28, he can post a message at 12:01 on March 29.
How can I do it?
Edit:
Here is my post_controller, can I get some help on how to reorganize this?
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
I tried something like this, but this, of course, is wrong:
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
validation ruby-on-rails time ruby-on-rails-3
trying_hal9000
source share