Permalink
Browse files

removed the need for slug. Slug created from title

  • Loading branch information...
1 parent 9c4c761 commit ba617ca1749d8529dc5bc178c441baeea9f6feb3 @pythonandchips pythonandchips committed Feb 20, 2012
View
10 app/controllers/spree/admin/pages_controller.rb
@@ -1,22 +1,28 @@
class Spree::Admin::PagesController < Spree::Admin::ResourceController
update.after :expire_cache
+ before_filter :parent_select
def index
@pages = Spree::Page.top_level
end
def new
- @pages = [Spree::Page.new(:title => 'No Parent')] + Spree::Page.all
@page = @object
end
def edit
- @pages = [Spree::Page.new(:title => 'No Parent')] + Spree::Page.all - [@object]
@page = @object
end
private
def expire_cache
expire_page :controller => '/spree/static_content', :action => 'show', :path => @object.slug
end
+
+ def parent_select
+ @pages = [Spree::Page.new(:title => 'No Parent')] + Spree::Page.all
+ if @object.present?
+ @pages = @pages - [@object]
+ end
+ end
end
View
8 app/models/spree/page.rb
@@ -14,14 +14,18 @@ class Spree::Page < ActiveRecord::Base
scope :sidebar_links, where(:show_in_sidebar => true).visible
- before_save :update_positions_and_slug
+ before_validation :update_positions_and_slug
def initialize(*args)
super(*args)
last_page = Spree::Page.last
self.position = last_page ? last_page.position + 1 : 0
end
+ def display_slug
+ slug.split('/').last
+ end
+
def link
if foreign_link.present?
return foreign_link
@@ -54,7 +58,7 @@ def not_using_foreign_link?
end
def slug_link
- page_slug = slug.split('/').last
+ page_slug = self.title.downcase.gsub(' ','-')
url = ensure_slash_prefix(page_slug)
url.prepend(self.parent.slug) if self.parent.present?
url
View
6 app/views/spree/admin/pages/_form.html.erb
@@ -6,12 +6,6 @@
<%= f.error_message_on :title %>
<% end %>
- <%= f.field_container :slug do %>
- <%= f.label :slug, t(:slug) %> <span class="required">*</span><br />
- <%= f.text_field :slug, :class => 'fullwidth title' %>
- <%= f.error_message_on :slug %>
- <% end %>
-
<%= f.field_container :body do %>
<%= f.label :body, t(:body) %><br />
<%= f.text_area :body, {:class => 'fullwidth'} %>
View
7 spec/models/page_spec.rb
@@ -4,7 +4,6 @@
before(:each) do
@page = Spree::Page.create(
:title => 'test page',
- :slug => 'test-page',
:body => 'this is a test page'
)
end
@@ -20,8 +19,7 @@
context "with parent page" do
before do
@parent_page = Spree::Page.create(
- :title => 'test page',
- :slug => 'parent-page',
+ :title => 'parent page',
:body => 'this is a test page'
)
@page.parent = @parent_page
@@ -35,8 +33,7 @@
context "with grandparent page" do
before do
@grandparent_page = Spree::Page.create(
- :title => 'test page',
- :slug => 'grandparent-page',
+ :title => 'grandparent page',
:body => 'this is a test page'
)
@parent_page.parent = @grandparent_page

0 comments on commit ba617ca

Please sign in to comment.