diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 46dec485c..2f174877f 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -60,6 +60,23 @@ class WikiController < ApplicationController @pages_by_date = @pages.group_by {|p| p.updated_on.to_date} end + def new + @page = WikiPage.new(:wiki => @wiki, :title => params[:title]) + unless User.current.allowed_to?(:edit_wiki_pages, @project) && editable? + render_403 + end + if request.post? + @page.validate + if @page.errors[:title].blank? + path = project_wiki_page_path(@project, @page.title) + respond_to do |format| + format.html { redirect_to path } + format.js { render :js => "window.location = #{path.to_json}" } + end + end + end + end + # display a page (in editing mode if it doesn't exist) def show if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7edfbd534..7cdf5061a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1057,11 +1057,17 @@ module ApplicationHelper fields_for(*args, &proc) end + # Render the error messages for the given objects def error_messages_for(*objects) - html = "" objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact errors = objects.map {|o| o.errors.full_messages}.flatten - if errors.any? + render_error_messages(errors) + end + + # Renders a list of error messages + def render_error_messages(errors) + html = "" + if errors.present? html << "