##// END OF EJS Templates
removed project_id presence validation on wiki model which was failing when creating a project with a wiki...
Jean-Philippe Lang -
r332:56d0af472d62
parent child
Show More
@@ -1,44 +1,44
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Wiki < ActiveRecord::Base
18 class Wiki < ActiveRecord::Base
19 belongs_to :project
19 belongs_to :project
20 has_many :pages, :class_name => 'WikiPage', :dependent => :destroy
20 has_many :pages, :class_name => 'WikiPage', :dependent => :destroy
21
21
22 validates_presence_of :project_id, :start_page
22 validates_presence_of :start_page
23
23
24 # find the page with the given title
24 # find the page with the given title
25 # if page doesn't exist, return a new page
25 # if page doesn't exist, return a new page
26 def find_or_new_page(title)
26 def find_or_new_page(title)
27 title = Wiki.titleize(title || start_page)
27 title = Wiki.titleize(title || start_page)
28 find_page(title) || WikiPage.new(:wiki => self, :title => title)
28 find_page(title) || WikiPage.new(:wiki => self, :title => title)
29 end
29 end
30
30
31 # find the page with the given title
31 # find the page with the given title
32 def find_page(title)
32 def find_page(title)
33 pages.find_by_title(Wiki.titleize(title || start_page))
33 pages.find_by_title(Wiki.titleize(title || start_page))
34 end
34 end
35
35
36 # turn a string into a valid page title
36 # turn a string into a valid page title
37 def self.titleize(title)
37 def self.titleize(title)
38 # replace spaces with _ and remove unwanted caracters
38 # replace spaces with _ and remove unwanted caracters
39 title = title.gsub(/\s+/, '_').delete(',;|') if title
39 title = title.gsub(/\s+/, '_').delete(',;|') if title
40 # upcase the first letter
40 # upcase the first letter
41 title = title[0..0].upcase + title[1..-1] if title
41 title = title[0..0].upcase + title[1..-1] if title
42 title
42 title
43 end
43 end
44 end
44 end
General Comments 0
You need to be logged in to leave comments. Login now