Last active
December 15, 2015 18:19
-
-
Save dcvezzani/5303031 to your computer and use it in GitHub Desktop.
For some reason, the routes for the BcmsMy401k::Engine are being applied twice. Obviously, the cause should be chased down, but since this only takes place when the application is loaded, it shouldn't be too big a deal in the short run to check and see if the routes were already drawn before drawing them again. The config/routes.rb depends on th…
This file contains 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
# config/routes.rb | |
BrowsercmsDemo::Application.routes.draw do | |
... | |
mount_bcms_my401k | |
mount_browsercms | |
end | |
... | |
BcmsMy401k::Engine.routes.draw do | |
# TODO: need to figure out why this is getting called twice during start up | |
# check if routes were already drawn before drawing them again | |
if(BcmsMy401k::Engine.routes.named_routes.names.length == 0) | |
content_blocks :layouts | |
content_blocks :articles | |
end | |
end |
This file contains 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
# lib/bcms_my401k/engine.rb | |
require 'browsercms' | |
module BcmsMy401k | |
class Engine < ::Rails::Engine | |
include Cms::Module | |
isolate_namespace BcmsMy401k | |
config.to_prepare do | |
# Each helper that is included must be loaded here from the BcmsMy401k namespace | |
# and included in the Cms::ViewContext and ApplicationHelper so it may be accessible | |
%W{Article Layout}.each do |resource| | |
Cms::ViewContext.send(:include, BcmsMy401k.module_eval("#{resource.pluralize}Helper")) | |
ApplicationHelper.send(:include, BcmsMy401k.module_eval("#{resource.pluralize}Helper")) | |
end | |
end | |
initializer 'bcms_my401k.route_extensions', :after => 'action_dispatch.prepare_dispatcher' do |app| | |
ActionDispatch::Routing::Mapper.send :include, BcmsMy401k::RouteExtensions | |
end | |
end | |
end |
This file contains 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
# lib/bcms_my401k/route_extensions.rb | |
module BcmsMy401k::RouteExtensions | |
def mount_bcms_my401k | |
mount BcmsMy401k::Engine => "/bcms_my401k" | |
# add extra routes that should be always be present | |
# e.g., match '/blog/feeds', :to=>"bcms_blog/feeds#index", :defaults=>{:format => "rss"}, :as=>'blog_feeds' | |
end | |
alias :routes_for_bcms_my401k :mount_bcms_my401k | |
end | |
This file contains 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
# lib/bcms_my401k.rb | |
require "bcms_my401k/engine" | |
require 'bcms_my401k/route_extensions' | |
module BcmsMy401k | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment