Ruby on rails验证代码不起作用

时间:2015-05-19 02:33:51

标签: ruby-on-rails-3 ruby-on-rails-4

这里有错吗?我希望条目以http://amzn.com/w/开头,后跟任何内容。但是,无论我输入什么,我都会收到错误消息。

validates :wl_url, format: { with: /\A(http:\/\/amzn\.com\/w\/)+([a-z0-9]*)\z/, 
  message: 'Please make sure the Wish List code starts with http://amzn.com/w/, if unsure see "how it works" page for instructions.'}

1 个答案:

答案 0 :(得分:0)

试试这个语法:

validates_format_of :wl_url, :with => /\A(http:\/\/amzn\.com\/w\/)+([a-z0-9]*)\z/i, :message => "Please make sure the Wish List code starts with http://amzn.com/w/, if unsure see "how it works" page for instructions."