Last active
December 10, 2015 12:29
-
-
Save jess/4434676 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /app/decorators/controllers/refinery/pages/pages_controller_decorator.rb | |
Refinery::PagesController.class_eval do | |
def show | |
if current_user_can_view_page? | |
if should_skip_to_first_child? | |
redirect_to refinery.url_for(first_live_child.url) | |
elsif page.link_url.present? && redirect_url? | |
redirect_to page.link_url | |
else | |
if requested_friendly_id != page.friendly_id && redirect_url? | |
redirect_to refinery.url_for(page.url), :status => 301 | |
else | |
render_with_templates? | |
end | |
end | |
else | |
error_404 | |
end | |
end | |
def redirect_url? | |
page.link_url[0] == "/" | |
end | |
def find_page(fallback_to_404 = true) | |
@page ||= case action_name | |
when "home" | |
Refinery::Page.where(:link_url => '/').first | |
when "show" | |
Refinery::Page.find_by_path_or_id(params[:path], params[:id]) || Refinery::Page.where(:link_url => "#{params[:path]}").first | |
end | |
@page || (error_404 if fallback_to_404) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If
link_url
isnil
you'll get the following:Why not just put the
page.link_url.present?
check insideredirect_url?