Skip to content

Commit

Permalink
adds the ability for a page to redirect immediately to its first chil…
Browse files Browse the repository at this point in the history
…d if it has a child that is not a draft page if that option is set in refinery/admin/pages/page/edit.
  • Loading branch information
parndt committed Aug 22, 2009
1 parent 8b801ad commit c475fef
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions db/migrate/20090822092032_add_skip_to_first_child_to_pages.rb
@@ -0,0 +1,9 @@
class AddSkipToFirstChildToPages < ActiveRecord::Migration
def self.up
add_column :pages, :skip_to_first_child, :boolean, :default => false
end

def self.down
remove_column :pages, :skip_to_first_child
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20090618044141) do
ActiveRecord::Schema.define(:version => 20090822092032) do

create_table "images", :force => true do |t|
t.integer "parent_id"
Expand Down Expand Up @@ -87,6 +87,7 @@
t.integer "custom_title_image_id"
t.boolean "draft", :default => false
t.string "browser_title"
t.boolean "skip_to_first_child", :default => false
end

create_table "portfolio_entries", :force => true do |t|
Expand Down
6 changes: 6 additions & 0 deletions vendor/plugins/pages/app/controllers/pages_controller.rb
Expand Up @@ -7,6 +7,12 @@ def home

def show
@page = Page.find(params[:id], :include => [:parts, :slugs])

# if the admin wants this to be a "placeholder" page which goes to its first child, go to that instead.
if @page.skip_to_first_child
first_live_child = @page.children.find_by_draft(false, :order => "position ASC")
redirect_to page_url(first_live_child) unless first_live_child.nil?
end
end

end
5 changes: 5 additions & 0 deletions vendor/plugins/pages/app/views/admin/pages/_form.html.erb
Expand Up @@ -68,6 +68,11 @@
</div>
</div>
</div>
<div class='field'>
<%= label_tag :skip_to_first_child? %>
<%= f.check_box :skip_to_first_child %>
<%= f.label :skip_to_first_child, "Check this box if you want the visitor to be redirected to this page's first child page if this page is selected.", :class => "stripped" %>
</div>
<div class='field'>
<%= f.label :link_url, "Custom URL" %>
<%= f.text_field :link_url, {:size => 103} %><br/>
Expand Down

0 comments on commit c475fef

Please sign in to comment.