fixes crash when selected "history" in preview of page being created

- history button is hidden in newly created page preview as it makes no sense
- redirect to '/' if page does not exist yet
This commit is contained in:
Michał Budzyński
2014-01-31 02:43:03 +01:00
parent 7a59d37350
commit 8b6b0699e5
3 changed files with 14 additions and 2 deletions
+7 -2
View File
@@ -341,8 +341,12 @@ module Precious
get '/history/*' do
@page = wiki_page(params[:splat].first).page
@page_num = [params[:page].to_i, 1].max
@versions = @page.versions :page => @page_num
mustache :history
unless @page.nil?
@versions = @page.versions :page => @page_num
mustache :history
else
redirect to("/")
end
end
post '/compare/*' do
@@ -454,6 +458,7 @@ module Precious
# Extensions and layout data
@editable = true
@page_exists = !page.versions.empty?
@toc_content = wiki.universal_toc ? @page.toc_data : nil
@mathjax = wiki.mathjax
@h1_title = wiki.h1_title
+3
View File
@@ -30,8 +30,11 @@ Mousetrap.bind(['e'], function( e ) {
<li class="minibutton"><a href="{{base_url}}/edit/{{escaped_url_path}}"
class="action-edit-page">Edit</a></li>
{{/editable}}
{{#page_exists}}
<li class="minibutton jaws">
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
class="action-page-history">History</a></li>
{{/page_exists}}
</ul>
</div>
<div id="wiki-content">
+4
View File
@@ -43,6 +43,10 @@ module Precious
@editable
end
def page_exists
@page_exists
end
def allow_uploads
@allow_uploads
end