禁止保存一些单词

时间:2012-07-31 21:48:18

标签: ruby-on-rails ruby ruby-on-rails-3 reserved-words

  • ruby​​ 1.9.2p290
  • rails 3.1.1

我有以下路线输出:

http://localhost:3001/chefs/peter (shows the chef profile **based on username**)
http://localhost:3001/chefs/edit (can edit their profile if logged)

如何阻止用户创建已具有修改等操作名称的用户名?

1 个答案:

答案 0 :(得分:1)

我认为应该有多个解决方案,但使用排除验证应该有效。

validates :name, :exclusion => { :in => %w(edit show) }