Add nested route url
This commit is contained in:
parent
e11dc5dd83
commit
66a462faa8
|
@ -5,7 +5,8 @@ class Item
|
||||||
key :_type, String
|
key :_type, String
|
||||||
|
|
||||||
key :name, String, :required => true, :index => true
|
key :name, String, :required => true, :index => true
|
||||||
|
key :full_name, String, :required => true, :index => true
|
||||||
|
|
||||||
key :parent_name, String, :index => true
|
key :parent_name, String, :index => true
|
||||||
key :parent_id, ObjectId, :index => true
|
key :parent_id, ObjectId, :index => true
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ class Item
|
||||||
key :is_published, Boolean, :required => true, :default => true, :index => true
|
key :is_published, Boolean, :required => true, :default => true, :index => true
|
||||||
|
|
||||||
validates_format_of :name, :with => /^[a-zA-Z-_]+$/
|
validates_format_of :name, :with => /^[a-zA-Z-_]+$/
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name, :scope => :parent_id
|
||||||
|
|
||||||
belongs_to :parent, :class_name => "Item", :foreign_key => :parent_id
|
belongs_to :parent, :class_name => "Item", :foreign_key => :parent_id
|
||||||
many :children, :class_name => "Item", :foreign_key => :parent_id, :dependent => :destroy
|
many :children, :class_name => "Item", :foreign_key => :parent_id, :dependent => :destroy
|
||||||
|
@ -32,6 +33,12 @@ class Item
|
||||||
nodes.reverse
|
nodes.reverse
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
urls = ancestors.map{ |a| a.name } << self.name
|
||||||
|
urls.delete("root")
|
||||||
|
"/#{urls.join("/")}"
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def setup_default_value
|
def setup_default_value
|
||||||
|
|
|
@ -3,6 +3,8 @@ class Snippet
|
||||||
include MongoMapper::Document
|
include MongoMapper::Document
|
||||||
|
|
||||||
key :name, String, :required => true, :index => true
|
key :name, String, :required => true, :index => true
|
||||||
|
key :full_name, String, :required => true, :index => true
|
||||||
|
|
||||||
key :parent_name, String, :required => true, :index => true
|
key :parent_name, String, :required => true, :index => true
|
||||||
key :parent_id, ObjectId, :required => true, :index => true
|
key :parent_id, ObjectId, :required => true, :index => true
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<td><%= item.position %></td>
|
<td><%= item.position %></td>
|
||||||
<td><%= item.is_published.to_s %></td>
|
<td><%= item.is_published.to_s %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to t(:show), admin_component_path(item.name) %> |
|
<%= link_to t(:show), item.url %> |
|
||||||
<%= link_to t(:edit), edit_admin_component_path(item) %> |
|
<%= link_to t(:edit), edit_admin_component_path(item) %> |
|
||||||
<%= link_to t(:delete), admin_component_path(item), :confirm => 'Are you sure?', :method => :delete %>
|
<%= link_to t(:delete), admin_component_path(item), :confirm => 'Are you sure?', :method => :delete %>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<td><%= item.position %></td>
|
<td><%= item.position %></td>
|
||||||
<td><%= item.is_published.to_s %></td>
|
<td><%= item.is_published.to_s %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to t(:show), admin_link_path(item.name) %> |
|
<%= link_to t(:show), item.url %> |
|
||||||
<%= link_to t(:edit), edit_admin_link_path(item) %> |
|
<%= link_to t(:edit), edit_admin_link_path(item) %> |
|
||||||
<%= link_to t(:delete), admin_link_path(item), :confirm => 'Are you sure?', :method => :delete %>
|
<%= link_to t(:delete), admin_link_path(item), :confirm => 'Are you sure?', :method => :delete %>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<td><%= item.position %></td>
|
<td><%= item.position %></td>
|
||||||
<td><%= item.is_published.to_s %></td>
|
<td><%= item.is_published.to_s %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to t(:show), admin_page_path(item.name) %> |
|
<%= link_to t(:show), item.url %> |
|
||||||
<%= link_to t(:edit), edit_admin_page_path(item) %> |
|
<%= link_to t(:edit), edit_admin_page_path(item) %> |
|
||||||
<%= link_to t(:delete), admin_page_path(item), :confirm => 'Are you sure?', :method => :delete %>
|
<%= link_to t(:delete), admin_page_path(item), :confirm => 'Are you sure?', :method => :delete %>
|
||||||
</td>
|
</td>
|
||||||
|
|
Reference in New Issue