diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-11-18 16:01:07 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-11-18 16:01:07 +0000 |
commit | f36b3fff60473dec197f17f632213785a6982382 (patch) | |
tree | 9d8659f6f9122d7e0a1490a987cd480df1ad3dba /app | |
parent | 46d27348fd60128b7d220d209f6d9382003aa165 (diff) | |
download | redmine-f36b3fff60473dec197f17f632213785a6982382.tar.gz redmine-f36b3fff60473dec197f17f632213785a6982382.zip |
Code cleanup.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10842 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/wiki_controller.rb | 13 | ||||
-rw-r--r-- | app/models/wiki_page.rb | 15 |
2 files changed, 17 insertions, 11 deletions
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 24fae9340..5d8d326ba 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -141,15 +141,6 @@ class WikiController < ApplicationController end content_params ||= {} - if !@page.new_record? && content_params.present? && @content.text == content_params[:text] - attachments = Attachment.attach_files(@page, params[:attachments]) - render_attachment_warning_if_needed(@page) - # don't save content if text wasn't changed - @page.save - redirect_to :action => 'show', :project_id => @project, :id => @page.title - return - end - @content.comments = content_params[:comments] @text = content_params[:text] if params[:section].present? && Redmine::WikiFormatting.supports_section_edit? @@ -161,8 +152,8 @@ class WikiController < ApplicationController @content.text = @text end @content.author = User.current - @page.content = @content - if @page.save + + if @page.save_with_content attachments = Attachment.attach_files(@page, params[:attachments]) render_attachment_warning_if_needed(@page) call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 17e0a4c4f..c275cd83e 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -173,6 +173,21 @@ class WikiPage < ActiveRecord::Base self.parent = parent_page end + # Saves the page and its content if text was changed + def save_with_content + ret = nil + transaction do + if new_record? + # Rails automatically saves associated content + ret = save + else + ret = save && (content.text_changed? ? content.save : true) + end + raise ActiveRecord::Rollback unless ret + end + ret + end + protected def validate_parent_title |