From 5f976b4483609fbcd32236c92459df2527c30947 Mon Sep 17 00:00:00 2001 From: hukl Date: Sat, 7 Feb 2009 15:51:29 +0100 Subject: added new helper code to create links for a given node path. --- app/helpers/link_helper.rb | 12 ++++++++++++ app/models/node.rb | 5 +++++ app/views/pages/index.html.erb | 5 +---- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 app/helpers/link_helper.rb diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb new file mode 100644 index 0000000..68586c1 --- /dev/null +++ b/app/helpers/link_helper.rb @@ -0,0 +1,12 @@ +module LinkHelper + + def link_to_path path + url_for( + :controller => :content, + :action => :render_page, + :language => I18n.locale, + :page_path => path + ) + end + +end \ No newline at end of file diff --git a/app/models/node.rb b/app/models/node.rb index a1d8af0..e08e228 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -33,6 +33,11 @@ class Node < ActiveRecord::Base # Instance Methods + # returns an array with all parts of a unique_name rather than a string + def unique_path + unique_name.split("/") rescue unique_name + end + # returns array with pages up to root excluding root def path_to_root parent.nil? && [slug] || parent.path_to_root.push(slug) diff --git a/app/views/pages/index.html.erb b/app/views/pages/index.html.erb index 41c8bae..f5918f0 100644 --- a/app/views/pages/index.html.erb +++ b/app/views/pages/index.html.erb @@ -13,10 +13,7 @@ <%=h page.node_id %> <%=h page.title %> - <%=h page.abstract %> - <%=h page.body %> - <%=h page.revision %> - <%= link_to 'Show', page %> + <%= link_to 'Show', link_to_path(page.node.unique_path) %> <%= link_to 'Edit', edit_page_path(page) %> <%= link_to 'Destroy', page, :confirm => 'Are you sure?', :method => :delete %> -- cgit v1.3