Add an ordering scope to Wiki
This commit is contained in:
parent
5aada8cc2a
commit
167f26b90d
2 changed files with 10 additions and 8 deletions
|
@ -2,16 +2,16 @@ class WikisController < ProjectResourceController
|
||||||
before_filter :authorize_read_wiki!
|
before_filter :authorize_read_wiki!
|
||||||
before_filter :authorize_write_wiki!, only: [:edit, :create, :history]
|
before_filter :authorize_write_wiki!, only: [:edit, :create, :history]
|
||||||
before_filter :authorize_admin_wiki!, only: :destroy
|
before_filter :authorize_admin_wiki!, only: :destroy
|
||||||
|
|
||||||
def pages
|
def pages
|
||||||
@wikis = @project.wikis.group(:slug).order("created_at")
|
@wiki_pages = @project.wikis.group(:slug).ordered
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
if params[:old_page_id]
|
if params[:version_id]
|
||||||
@wiki = @project.wikis.find(params[:old_page_id])
|
@wiki = @project.wikis.find(params[:version_id])
|
||||||
else
|
else
|
||||||
@wiki = @project.wikis.where(slug: params[:id]).order("created_at").last
|
@wiki = @project.wikis.where(slug: params[:id]).ordered.first
|
||||||
end
|
end
|
||||||
|
|
||||||
@note = @project.notes.new(noteable: @wiki)
|
@note = @project.notes.new(noteable: @wiki)
|
||||||
|
@ -29,7 +29,7 @@ class WikisController < ProjectResourceController
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@wiki = @project.wikis.where(slug: params[:id]).order("created_at").last
|
@wiki = @project.wikis.where(slug: params[:id]).ordered.first
|
||||||
@wiki = Wiki.regenerate_from @wiki
|
@wiki = Wiki.regenerate_from @wiki
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,9 +47,9 @@ class WikisController < ProjectResourceController
|
||||||
end
|
end
|
||||||
|
|
||||||
def history
|
def history
|
||||||
@wikis = @project.wikis.where(slug: params[:id]).order("created_at")
|
@wiki_pages = @project.wikis.where(slug: params[:id]).ordered
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@wikis = @project.wikis.where(slug: params[:id]).delete_all
|
@wikis = @project.wikis.where(slug: params[:id]).delete_all
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ class Wiki < ActiveRecord::Base
|
||||||
|
|
||||||
before_update :set_slug
|
before_update :set_slug
|
||||||
|
|
||||||
|
scope :ordered, order("created_at DESC")
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
slug
|
slug
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue