Skip to content

Commit

Permalink
Merge pull request SpinaCMS#136 from katafrakt/fix-path-for-non-stand…
Browse files Browse the repository at this point in the history
…ard-root

Fix urls in menu with non-standard backend_path
  • Loading branch information
Bram Jetten committed Apr 25, 2016
2 parents d4e8088 + ecf6dde commit 4a0ddfe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/controllers/spina/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ def rewrite_page
end

def page
@page ||= (action_name == 'homepage') ? Page.find_by!(name: 'homepage') : Page.with_translations(I18n.locale).find_by!(materialized_path: request.path) || Page.with_translations(I18n.default_locale).find_by!(materialized_path: request.path)
@page ||= (action_name == 'homepage') ? Page.find_by!(name: 'homepage') : Page.with_translations(I18n.locale).find_by!(materialized_path: materialized_path) || Page.with_translations(I18n.default_locale).find_by!(materialized_path: request.path)
end
helper_method :page

def materialized_path
segments = ['/', params[:locale], params[:id]].compact
File.join(*segments)
end

def current_user_can_view_page?
raise ActiveRecord::RecordNotFound unless page.live? || current_user.present?
end
Expand Down
3 changes: 2 additions & 1 deletion app/presenters/spina/pages/menu_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ def render_menu_items(menu_items)

def render_menu_item(menu_item, index, menu_items_length)
content_tag(list_item_tag, class: menu_item_css(menu_item[0], index, menu_items_length)) do
path = File.join(Spina::Engine.routes.url_helpers.root_path, menu_item[0].materialized_path)
buffer = ActiveSupport::SafeBuffer.new
buffer << link_to(menu_item[0].menu_title, menu_item[0].materialized_path)
buffer << link_to(menu_item[0].menu_title, path)
buffer << render_list_wrapper(menu_item[1])
buffer
end
Expand Down

0 comments on commit 4a0ddfe

Please sign in to comment.