0

I fully understand captcha, and already implemented to my app. It's working fine so far.
Obviously, it'll be annoying if it asks you captcha code to type in every time you wanna post:(

Now I'm thinking of the way comparing current time with the time the user posed last time. If it's Post model, and it has its created_at(Timestamp)

How can I write in my controller? I'd like to use 'before filter' checking when it does create. and I want user to wait at least 1 min to post next post.

should it be something like this below? I'm so newbie to Rails. Please help!

def spam_check

 @post = Post.find_by_user_id(current_user.id)
 lasttime = @post.created_at.last


end
4

2 に答える 2

5

あなたのPostモデルで:

validate :spam_check?, :on => :create

def spam_check?
   @post = Post.find_all_by_user_id(current_user.id).last
   last_time = @post.created_at

   Time.now - last_time > 1.minute
end
于 2012-12-11T07:58:09.403 に答える
1

JS を使用して、送信前にフォームの非表示フィールドに自動的に入力することができます。また、誰かが JS を無効にしている場合は、キャプチャを表示するだけです。

編集: @sub_stantial の投稿に加えて良い考えです。

于 2012-12-11T08:54:29.280 に答える