【发布时间】:2020-09-27 12:52:40
【问题描述】:
我正在学习编程,并且正在尝试使用 Ruby on rails。我想限制一项允许用户向我发送介绍请求的功能(每 30 天 3 个介绍请求)。我不确定是否必须先创建一个方法,例如:
def month
where("created_at <?", Date.today - 30.days))
end
我不知道那个方法是否正确,是否可以将它集成到这段代码中:
def create
@introduction = CompanyIntroduction.create(intro_params)
if current_user #Admin can edit the user name and email
@introduction.user = current_user
@introduction.user_name = current_user.full_name
@introduction.user_email = current_user.email
end
if @introduction.save
flash[:success] = "Thank you. Your request is being reviewed by TechIreland."
else
flash[:error] = @introduction.errors.full_messages
end
redirect_back(fallback_location: user_companies_path)
end
【问题讨论】:
标签: ruby-on-rails function time limit