除数字数字外,它不接受文本。我在我的模型的page.rb中创建了一个私有方法,它不能从外部模型:page.rb调用,以便自动修复用户的永久链接,因为它没有提供。尽管如此,除了数字之外,仍然没有文字。
以下是我的模型中代码的一些细节:
page.rb
class Page < ActiveRecord::Base
belongs_to :subject
has_many :sections
has_and_belongs_to_many :editors, :class_name => 'AdminUser'
acts_as_list :scope => :subject
before_validation :add_default_permalink
after_save :touch_subject
validates_presence_of :name
validates_length_of :name, :maximum => 255
validates_presence_of :permalink
validates_length_of :permalink, :within => 3..255
# use presence_of with length_of to disallow spaces
validates_uniqueness_of :permalink
# for unique values by subject use ":scope => :subject_id"
scope :visible, lambda {where(:visible => true)}
scope :invisible, lambda {where(:visible => false)}
scope :sorted, lambda {order('pages.position ASC')}
scope :newest_first, lambda {order('pages.created_at DESC')}
scope :search, lambda {|query| where('name LIKE ?', "%#{query}%")}
private
def add_default_permalink
if permalink.blank?
self.permalink = "#{id}-#{name.parameterize}"
end
end
def touch_subject
# touch is similar to:
# subject.update_attributes(updated_at, Time.now)
subject.touch
end
end
请点击此处查看错误
如果我为此添加最多3个数字或只输入数字,那么该程序运行良好,不会单独使用文本。