Wiki: history

This commit is contained in:
Valery Sizov 2012-02-19 21:52:05 +02:00
parent b565cd1972
commit 85974948e7
7 changed files with 41 additions and 4 deletions

View file

@ -4,7 +4,11 @@ class WikisController < ApplicationController
layout "project"
def show
@wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last
if params[:old_page_id]
@wiki = @project.wikis.find(params[:old_page_id])
else
@wiki = @project.wikis.where(:slug => params[:id]).order("created_at").last
end
respond_to do |format|
if @wiki
format.html
@ -22,6 +26,7 @@ class WikisController < ApplicationController
def create
@wiki = @project.wikis.new(params[:wiki])
@wiki.user = current_user
respond_to do |format|
if @wiki.save
@ -31,6 +36,10 @@ class WikisController < ApplicationController
end
end
end
def history
@wikis = @project.wikis.where(:slug => params[:id]).order("created_at")
end
def destroy
@wiki = @project.wikis.find(params[:id])

View file

@ -1,7 +1,8 @@
class Wiki < ActiveRecord::Base
belongs_to :project
belongs_to :user
validates :content, :title, :presence => true
validates :content, :title, :user_id, :presence => true
validates :title, :length => 1..250
before_update :set_slug

View file

@ -0,0 +1,14 @@
%h2 Versions
%table
%thead
%tr
%th #
%th last edit
%th created by
%tbody
- @wikis.each_with_index do |wiki_page, i|
%tr
%td= i + 1
%td= link_to wiki_page.created_at.to_s(:short), project_wiki_path(@project, wiki_page, :old_page_id => wiki_page.id)
%td= wiki_page.user.name

View file

@ -1,6 +1,8 @@
%h3
= @wiki.title
- if can? current_user, :write_wiki, @project
= link_to history_project_wiki_path(@project, @wiki), :class => "right btn small" do
History
= link_to edit_project_wiki_path(@project, @wiki), :class => "right btn small" do
Edit