我不确定确保每个用户都具有某些必要属性的最佳方法,并且如果他们不是我想将其重定向到“新”页面,例如带重定向的应用程序控制器级别验证
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :authenticate_user!, :valid_location
def valid_location
if (current_user.location.nil? || current_user.location.city.nil?)
redirect_to new_user_locations_path(current_user.id)
else
true
end
end
上面的例子有缺陷,因为它创建了一个重定向循环。我可以明确地使用一些关于创建这种验证的建议。谢谢
,只需添加'skip_before_filter:valid_location ,只有::new来修复重定向循环。还有,你不需要返回true,所以只需删除其他部分。 – jvnill 2014-10-28 03:43:09