Accept terms of use rails

前端 未结 2 1105
北海茫月
北海茫月 2021-02-05 19:36

What is the best way to add a check for accepting terms of use in a rails app?

I can\'t seem to get validates_acceptance_of working quite right. I added a b

2条回答
  •  清酒与你
    2021-02-05 20:05

    In your model,

    validates_acceptance_of :terms
    

    If you're using attr_accessible in your model then make sure you also add,

    attr_accessible :terms
    

    In your view,

    <%= form_for @user do |f| %>
      ...
      <%= f.check_box :terms %>
      ...
    <% end %>
    

    There is no need for an extra column in the users table unless you plan on denying access to users who have not accepted the terms of service, which won't exist since they can't complete registration in the first place.

提交回复
热议问题