我有这个代码
我有这些选项,如果用户选择“不列颠哥伦比亚省”以外的任何内容,给他错误消息,该省必须“不列颠哥伦比亚省”
我相信它会通过使用模型验证来解决
<%= f.label :province ,"Province (required)"%><br>
<%= f.select(:province, [["Select One", ""],'Alberta','British Columbia','Manitoba','New Brunswick','Newfoundland and Labrador','Nova Scotia','Northwest Territories','Nunavut','Ontario','Prince Edward Island','Quebec','Saskatchewan','Yukon'], {}) %>
用户.rb
validates :province, presence: "British Columbia"