【发布时间】:2016-12-07 01:11:05
【问题描述】:
我有一个 Rails 应用程序,它制作了一个离子(角度)应用程序使用的 API。在我的用户注册中,我要求用户在注册前同意服务条款,并将其设置在我控制器的参数中。
模型面是这样的:
# agreeing to terms of service
validates_acceptance_of :terms_of_service, on: :create
控制器如下所示:
def mobile_user_params
allowed = [:first_name, :last_name, :email, :password, :password_confirmation, :location, :terms_of_service]
params.require(:user).permit(allowed)
end
参数中的最终结果如下所示:
{"user"=>{"terms_of_service"=>true}, "controller"=>"users", "action"=>"mobile_create", "format"=>"json"}
我的问题是什么,即使它返回 {"terms_of_service"=>true} 因为我接受它,这也会返回一条错误消息:
errors: {"Terms of Service must be accepted"}
有谁知道我怎样才能满足这个验证?它在使用复选框呈现 HTML 时有效,但在 JSON 请求上我似乎无法满足它。
非常感谢任何帮助。
【问题讨论】:
标签: ruby-on-rails angularjs json