【问题标题】:Prohibit some words from being saved禁止某些单词被保存
【发布时间】:2012-07-31 21:48:18
【问题描述】:
  • 红宝石 1.9.2p290
  • 导轨 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)

如何防止用户创建已具有edit等操作名称的用户名?

【问题讨论】:

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


    【解决方案1】:

    我认为应该有不止一种解决方案,但使用排除验证应该可行。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-13
      • 2016-02-19
      • 1970-01-01
      • 2015-12-31
      • 2015-06-14
      相关资源
      最近更新 更多