我在我的 rails 应用程序中为我的路线使用friendly_id 。
我想确保数字 id 不能访问页面。
可以像这样访问页面 - www.myurl.com/myfriendlyidstub
该页面不应像这样访问 - www.myurl.com/12345(12345 是 myfriendlyidstub 的 id)
我在friendly_id 的文档中看不到这样做的方法。
所以我正在考虑在我的控制器中添加一个方法来检查参数是否为数字
def edit
if params[:id].is_numeric? #I need to know how to write this method
not_found #not_found redirects to a 404
end
#rest of the edit action
end
两个问题——
如何编写“is_numeric”方法?
这是做事的好方法吗?你能看出什么陷阱吗?