Last active
January 10, 2017 18:45
-
-
Save timdiggins/bf6d09b28828a392198562c93554ad07 to your computer and use it in GitHub Desktop.
MainAppDelegator
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
# config/intitializers/thredded.rb | |
# to allow you to not to have to add `main_app` before every path helper | |
# when embedding Thredded within a main-app supplied layout (with navbar and links to the main_app) | |
# ... Add this to the bottom of the initializer | |
Rails.application.config.to_prepare do | |
Rails.application.reload_routes! | |
thredded_methods = (Thredded::Engine.routes.url_helpers.methods + Thredded::UrlsHelper.instance_methods) | |
.select { |s| s.to_s.ends_with?("_path", "_url") } | |
main_app_delegator = Module.new do | |
Rails.application.routes.url_helpers.methods | |
.select { |m| m.to_s.ends_with?('_path', '_url') } | |
.reject { |m| thredded_path_methods.include?(m).tap { |r| Rails.logger.warn "ignoring conflict: #{m}" if r } } | |
.each{ |method_name| send(:define_method, method_name) {|*args| main_app.send(method_name, *args)} } | |
end | |
::Thredded::ApplicationController.helper main_app_delegator | |
end |
There's an error here. thredded_path_methods
doesn't exist it should be thredded_methods
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NB: there is a tempting much simpler solution:
Unfortunately this would define (and redefine) more than just the path and url helpers and would break existing routes in the Engine.