Skip to content
Browse files

Fix wikipage slugs and urls with friendlyid 4

  • Loading branch information...
1 parent bf72c97 commit 2a09b1405e70587d79951e821b0446d697b13409 @jamesu committed Oct 5, 2011
View
6 app/controllers/wiki_pages_controller.rb
@@ -59,7 +59,7 @@ def create
if @wiki_page.save
flash[:message] = I18n.t 'wiki_engine.success_creating_wiki_page'
- redirect_to @wiki_page.main ? wiki_pages_path : wiki_page_path(:id => @wiki_page)
+ redirect_to @wiki_page.main ? wiki_pages_path : wiki_page_path(:id => @wiki_page.slug)
else
render :action => 'new'
end
@@ -140,11 +140,11 @@ def find_main_wiki_page
end
def find_wiki_page
- @wiki_page = wiki_pages.where(:project_id => @active_project.id).find_by_title(params[:id])
+ @wiki_page = wiki_pages.where(:project_id => @active_project.id).find_by_slug(params[:id])
end
def find_sidebar_page
- @wiki_sidebar = wiki_pages.where(:project_id => @active_project.id).find_by_title("sidebar") rescue nil
+ @wiki_sidebar = wiki_pages.where(:project_id => @active_project.id).find_by_slug("sidebar") rescue nil
@content_for_sidebar = @wiki_sidebar.nil? ? nil : 'wiki_sidebar'
end
end
View
4 app/helpers/application_helper.rb
@@ -194,8 +194,8 @@ def actions_for_time_short(time)
end
def actions_for_wiki_page(page)
- [{:name => I18n.t('edit'), :url => {:controller => 'wiki_pages', :action => 'edit', :id => page}, :cond => can?(:edit,page)},
- {:name => I18n.t('delete'), :url => {:controller => 'wiki_pages', :action => 'destroy', :id => page}, :cond => can?(:delete,page), :method => :delete, :confirm => I18n.t('wiki_page_confirm_delete')}]
+ [{:name => I18n.t('edit'), :url => {:controller => 'wiki_pages', :action => 'edit', :id => page.slug}, :cond => can?(:edit,page)},
+ {:name => I18n.t('delete'), :url => {:controller => 'wiki_pages', :action => 'destroy', :id => page.slug}, :cond => can?(:delete,page), :method => :delete, :confirm => I18n.t('wiki_page_confirm_delete')}]
end
def running_time_for_task(task)
View
2 app/helpers/wiki_pages_helper.rb
@@ -98,6 +98,6 @@ def wiki_id_to_title(id)
end
def wiki_title_to_id(title)
- WikiPage.new(:title => title).slug_text
+ WikiPage.new(:title => title).normalize_friendly_id(title)
end
end
View
4 app/models/wiki_page.rb
@@ -5,7 +5,7 @@ class WikiPage < ActiveRecord::Base
before_save :set_main_page
acts_as_versioned :extend => WikiPageUser
- friendly_id :title, :use => :slugged, :slug_column => :title
+ friendly_id :title, :use => :slugged
validates_presence_of :title
def title_from_id=(id)
@@ -14,6 +14,8 @@ def title_from_id=(id)
belongs_to :project
self.non_versioned_columns << :project_id
+ self.non_versioned_columns << :title
+ self.non_versioned_columns << :slug
scope :main, lambda{ |project| where(:main => true, :project_id => project.id) }
after_create :process_create
View
2 app/views/wiki_pages/_list.html.erb
@@ -9,7 +9,7 @@
<tbody>
<% list.each do |wiki_page| %>
<tr class="<%= cycle('odd', 'even') %>">
- <td><%= link_to h(wiki_page.title), wiki_page_path(:id => wiki_page) %></td>
+ <td><%= link_to h(wiki_page.title), wiki_page_path(:id => wiki_page.slug) %></td>
<td><%= wiki_page.updated_at.to_s(:long) %></td>
<td class="operations"><%= render :partial => 'operations', :locals => {:wiki_page => wiki_page} %></td>
</tr>
View
2 app/views/wiki_pages/_widget.html.erb
@@ -4,7 +4,7 @@
<ul>
<% wiki_pages.each do |wiki_page| %>
- <li><%= link_to_unless_current h(wiki_page.title), wiki_page_path(wiki_page) %></li>
+ <li><%= link_to_unless_current h(wiki_page.title), wiki_page_path(:id => wiki_page.slug)) %></li>
<% end %>
</ul>
</div>
View
2 app/views/wiki_pages/edit.html.erb
@@ -1,4 +1,4 @@
-<%= form_for(@wiki_page, :url => wiki_page_path(:id => @wiki_page)) do |form| %>
+<%= form_for(@wiki_page, :url => wiki_page_path(:id => @wiki_page.slug)) do |form| %>
<%= render :partial => form %>
<div class="buttons">
<button class="submit" type="submit"><%= t('edit_page') %></button>
View
32 config/locales/en.yml
@@ -644,6 +644,38 @@ en:
product_signature: "Powered by <a href=\"http://rubyforge.org/projects/railscollab\">RailsCollab</a>"
+ wiki_engine:
+ success_creating_wiki_page: 'New wiki page has been created'
+ success_updating_wiki_page: 'The wiki page has been updated'
+ success_deleting_wiki_page: 'The wiki page has been deleted'
+ preview: 'Preview'
+ current_version: 'Current'
+ current_version_edited_by: 'Current by %{user}'
+ version: 'Version %{version}'
+ version_edited_by: 'Version %{version} by %{user}'
+ title: 'Title'
+ content: 'Content'
+ main_page: 'Main page'
+ create: 'Create'
+ update: 'Update'
+ cancel: 'Cancel'
+ new: 'New page'
+ edit: 'Edit'
+ delete: 'Delete'
+ confirm_deletion: 'Are you sure?'
+ no_main_page: 'There is no main page yet'
+ last_modified: 'Last modified'
+ last_modified_with_time: 'Last modified %{time}'
+ not_found: 'Page not found'
+ non_existing_page: 'This wiki page does not exist yet.'
+ create_it: 'Create it'
+ pages: 'Pages'
+ help:
+ link_to_format: '%{link} is supported. You can also use raw HTML.'
+ links_to_wiki_pages: 'Links to other wiki pages'
+ format_code: 'Format source code samples like this'
+ highlight_language: 'Specify programming language in the sample with <code>class="language"</code> on <code>code</code> element.'
+
# rails
date:
formats:
View
21 db/migrate/20111005191500_kill_slugs.rb
@@ -0,0 +1,21 @@
+class PageFix < ActiveRecord::Base
+ set_table_name 'wiki_pages'
+end
+
+class SlugFix < ActiveRecord::Base
+ set_table_name 'slugs'
+end
+
+class KillSlugs < ActiveRecord::Migration
+ def up
+ add_column :wiki_pages, :slug, :string
+ add_index :wiki_pages, :slug
+ PageFix.all.each do |page|
+ page.slug = SlugFix.where(:sluggable_type => 'WikiPage', :sluggable_id => page.id).first.try(:name)
+ end
+ end
+
+ def down
+ remove_column :wiki_pages, :slug
+ end
+end
View
4 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111004100837) do
+ActiveRecord::Schema.define(:version => 20111005191500) do
create_table "activities", :force => true do |t|
t.integer "project_id", :default => 0, :null => false
@@ -406,9 +406,11 @@
t.integer "version"
t.integer "project_id"
t.integer "created_by_id"
+ t.string "slug"
end
add_index "wiki_pages", ["main"], :name => "index_wiki_pages_on_main"
add_index "wiki_pages", ["project_id"], :name => "index_wiki_pages_on_project_id"
+ add_index "wiki_pages", ["slug"], :name => "index_wiki_pages_on_slug"
end

0 comments on commit 2a09b14

Please sign in to comment.
Something went wrong with that request. Please try again.