summaryrefslogtreecommitdiff
path: root/app/models/node.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/node.rb')
-rw-r--r--app/models/node.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/models/node.rb b/app/models/node.rb
new file mode 100644
index 0000000..d57b6b9
--- /dev/null
+++ b/app/models/node.rb
@@ -0,0 +1,28 @@
+require "mysql"
+
+class Node < ActiveRecord::Base
+ set_table_name "node"
+ belongs_to :location
+ belongs_to :person
+ has_many :ip
+
+ validates_presence_of :name, :location_id
+ validates_uniqueness_of :name, :scope => 'location_id'
+
+ validates_format_of :name,
+ :with => /^([0-9a-z]*)$/,
+ :on => :create
+ validates_format_of :name,
+ :with => /^([0-9a-z]*)$/,
+ :on => :save
+
+
+ def comment
+ # nl2br
+ read_attribute(:comment).gsub("\n\r","<br>").gsub("\r", "").gsub("\n", "<br />")
+ end
+
+ def self.create_node(params)
+ Node.create(params)
+ end
+end