Add validation for item.name, only allow [a-zA-z-_]

This commit is contained in:
Wen-Tien Chang 2010-01-28 17:30:35 +08:00
parent ce63c53605
commit 12de9d2514
2 changed files with 2 additions and 1 deletions

View File

@ -14,6 +14,7 @@ class Item
key :position, Integer, :required => true
key :is_published, Boolean, :required => true, :default => true, :index => true
validates_format_of :name, :with => /^[a-zA-Z-_]+$/
belongs_to :parent, :class_name => "Item", :foreign_key => :parent_id
many :children, :class_name => "Item", :foreign_key => :parent_id

View File

@ -9,7 +9,7 @@ class RerouteMiddleware
#Rails.logger.debug env.to_yaml
return @app.call(env) if env['REQUEST_URI'] =~ /^\/admin/
env['REQUEST_URI'] =~ /^\/([\w]*)/
env['REQUEST_URI'] =~ /^\/([a-zA-Z-_]*)/
parsed_entry_name = $1
entry = Item.find_by_name( parsed_entry_name )