Wiki: titulos canonicos
This commit is contained in:
@@ -164,7 +164,7 @@ class WikiController < ApplicationController
|
|||||||
params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?
|
params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?
|
||||||
@course = Course.find(params[:course_id])
|
@course = Course.find(params[:course_id])
|
||||||
|
|
||||||
params[:id] = @course.wiki_pages.find_by_title(params[:id]).id if params[:id] and !params[:id].is_numeric? and !@course.wiki_pages.find_by_title(params[:id]).nil?
|
params[:id] = @course.wiki_pages.find_by_canonical_title(params[:id].pretty_url).id if params[:id] and !params[:id].is_numeric? and !@course.wiki_pages.find_by_canonical_title(params[:id].pretty_url).nil?
|
||||||
@wiki_page = params[:id] ? @course.wiki_pages.find(params[:id]) : WikiPage.new(params[:wiki_page])
|
@wiki_page = params[:id] ? @course.wiki_pages.find(params[:id]) : WikiPage.new(params[:wiki_page])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class WikiPage < ActiveRecord::Base
|
|||||||
acts_as_paranoid_versioned
|
acts_as_paranoid_versioned
|
||||||
self.non_versioned_columns << 'position'
|
self.non_versioned_columns << 'position'
|
||||||
self.non_versioned_columns << 'deleted_at'
|
self.non_versioned_columns << 'deleted_at'
|
||||||
|
self.non_versioned_columns << 'canonical_title'
|
||||||
|
|
||||||
# Associacoes
|
# Associacoes
|
||||||
belongs_to :course
|
belongs_to :course
|
||||||
@@ -35,8 +36,13 @@ class WikiPage < ActiveRecord::Base
|
|||||||
# Valicacao
|
# Valicacao
|
||||||
generate_validations
|
generate_validations
|
||||||
validates_uniqueness_of :title, :scope => :course_id
|
validates_uniqueness_of :title, :scope => :course_id
|
||||||
|
validates_uniqueness_of :canonical_title, :scope => :course_id
|
||||||
validates_format_of :title, :with => /^[^0-9]/
|
validates_format_of :title, :with => /^[^0-9]/
|
||||||
|
|
||||||
|
def before_validation
|
||||||
|
self.canonical_title = self.title.pretty_url
|
||||||
|
end
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
begin
|
begin
|
||||||
self.content.format_wiki
|
self.content.format_wiki
|
||||||
@@ -46,7 +52,7 @@ class WikiPage < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
self.title.match(/^[-_a-z0-9]*$/i).nil? ? self.id.to_s : self.title
|
self.canonical_title
|
||||||
end
|
end
|
||||||
|
|
||||||
def WikiPage.diff(from, to)
|
def WikiPage.diff(from, to)
|
||||||
|
|||||||
@@ -16,6 +16,14 @@ class String
|
|||||||
%w[auto_link excerpt highlight sanitize simple_format strip_tags truncate word_wrap].each do |method|
|
%w[auto_link excerpt highlight sanitize simple_format strip_tags truncate word_wrap].each do |method|
|
||||||
eval "def #{method}(*args); ActionController::Base.helpers.#{method}(self, *args); end"
|
eval "def #{method}(*args); ActionController::Base.helpers.#{method}(self, *args); end"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pretty_url
|
||||||
|
self.mb_chars.normalize(:kd).
|
||||||
|
gsub(/[^\x00-\x7F]/n,'').
|
||||||
|
gsub(/[^a-z._0-9 -]/i,"").
|
||||||
|
gsub(/ +/,"_").
|
||||||
|
downcase.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Array
|
class Array
|
||||||
|
|||||||
12
db/migrate/20090907095812_canonical.rb
Normal file
12
db/migrate/20090907095812_canonical.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
class Canonical< ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
add_column :wiki_pages, :canonical_title, :string
|
||||||
|
WikiPage.find(:all).each do |wiki|
|
||||||
|
wiki.update_attribute(:canonical_title, wiki.title.pretty_url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
remove_column :wiki_pages, :canonical_title
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# This file is auto-generated from the current state of the database. Instead of editing this file,
|
# This file is auto-generated from the current state of the database. Instead of editing this file,
|
||||||
# please use the migrations feature of ActiveRecord to incrementally modify your database, and
|
# please use the migrations feature of Active Record to incrementally modify your database, and
|
||||||
# then regenerate this schema definition.
|
# then regenerate this schema definition.
|
||||||
#
|
#
|
||||||
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
|
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 36) do
|
ActiveRecord::Schema.define(:version => 20090907095812) do
|
||||||
|
|
||||||
create_table "attachments", :force => true do |t|
|
create_table "attachments", :force => true do |t|
|
||||||
t.string "file_name", :null => false
|
t.string "file_name", :null => false
|
||||||
@@ -102,8 +102,8 @@ ActiveRecord::Schema.define(:version => 36) do
|
|||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
|
|
||||||
add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
|
add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
|
||||||
|
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
|
||||||
|
|
||||||
create_table "users", :force => true do |t|
|
create_table "users", :force => true do |t|
|
||||||
t.string "login", :null => false
|
t.string "login", :null => false
|
||||||
@@ -147,6 +147,7 @@ ActiveRecord::Schema.define(:version => 36) do
|
|||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.integer "position"
|
t.integer "position"
|
||||||
t.datetime "deleted_at"
|
t.datetime "deleted_at"
|
||||||
|
t.string "canonical_title"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user