summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/attachment.rb6
-rw-r--r--app/models/message.rb4
-rw-r--r--app/models/wiki.rb3
-rw-r--r--app/models/wiki_page.rb5
4 files changed, 16 insertions, 2 deletions
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 82fcdadf5..2be4e1639 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -77,7 +77,11 @@ class Attachment < ActiveRecord::Base
def self.most_downloaded
find(:all, :limit => 5, :order => "downloads DESC")
end
-
+
+ def project
+ container.is_a?(Project) ? container : container.project
+ end
+
private
def sanitize_filename(value)
# get only the filename, not the whole path
diff --git a/app/models/message.rb b/app/models/message.rb
index 1f8dde540..935141b7f 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -34,4 +34,8 @@ class Message < ActiveRecord::Base
board.increment! :topics_count
end
end
+
+ def project
+ board.project
+ end
end
diff --git a/app/models/wiki.rb b/app/models/wiki.rb
index 8233c3d48..8d461a85b 100644
--- a/app/models/wiki.rb
+++ b/app/models/wiki.rb
@@ -31,7 +31,8 @@ class Wiki < ActiveRecord::Base
# find the page with the given title
def find_page(title)
- pages.find_by_title(Wiki.titleize(title || start_page))
+ title = start_page if title.blank?
+ pages.find_by_title(Wiki.titleize(title))
end
# turn a string into a valid page title
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index b7964a119..562465197 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -18,6 +18,7 @@
class WikiPage < ActiveRecord::Base
belongs_to :wiki
has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy
+ has_many :attachments, :as => :container, :dependent => :destroy
validates_presence_of :title
validates_format_of :title, :with => /^[^,\.\/\?\;\|\s]*$/
@@ -41,4 +42,8 @@ class WikiPage < ActiveRecord::Base
def self.pretty_title(str)
(str && str.is_a?(String)) ? str.tr('_', ' ') : str
end
+
+ def project
+ wiki.project
+ end
end