ruby on rails regexp或ends_with

时间:2016-03-25 13:31:16

标签: ruby-on-rails ruby regex yaml

我试图阻止用户过度采取某些行动。

我的问题是我不知道最好的方法是检查动作的路径是否与我在YAML文件中定义的路径相匹配。我认为它可能是正则表达式或类似$scope.clearDispatchData=function(){ $scope.viewOrderTable=true; $scope.viewDispatch=false; $scope.order_status=''; } 方法的东西。

目前我有以下半就绪代码。我不确定是否应该按照ends_with目前的方式定义路径,也不确定我是否在YAML中调用了正确的比较。

有人可以帮助我解释为什么他/她推荐的解决方案在这里最好吗?

YAML:

rack_attack.rb

rack_attack.rb

logins_ip:
    limit: 5
    period: 30
    path: /users/sign_in

post_comment_creation: 
    limit: 5
    period: 45
    # Full route is /posts/:post_id/post_comments but post_id not required
    # since I wanna prevent users from commenting more than 5/45sec to all the
    # posts. Yet I may could use some regex that matches any number.
    path: /post_comments

messages_creation:
    limit: 10
    period: 10
    # Here I need this exact route since I wanna prevent users from
    # messaging more than 10/10sec in a given conversation
    path: conversations/:conversation_id/messages

default:
    period: 60
    limit: 10
    method: POST

0 个答案:

没有答案