Skip to content

Commit

Permalink
Add Solidus install generator routing fix
Browse files Browse the repository at this point in the history
A second run of the generator mounts Spree::Core::Engine a second time.
  • Loading branch information
tvdeyen committed Dec 22, 2017
1 parent f9731a1 commit 819066b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/alchemy/solidus/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Engine < ::Rails::Engine

if SolidusSupport.solidus_gem_version < Gem::Version.new('2.5')
require 'alchemy/solidus/spree_custom_user_generator_fix'
require 'alchemy/solidus/spree_install_generator_fix'
end
end
end
Expand Down
29 changes: 29 additions & 0 deletions lib/alchemy/solidus/spree_install_generator_fix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'generators/spree/install/install_generator'

Spree::InstallGenerator.class_eval do
CORE_MOUNT_ROUTE = "mount Spree::Core::Engine"

def install_routes
routes_file_path = File.join('config', 'routes.rb')
unless File.read(routes_file_path).include? CORE_MOUNT_ROUTE
insert_into_file routes_file_path, after: "Rails.application.routes.draw do\n" do
<<-ROUTES
# This line mounts Solidus's routes at the root of your application.
# This means, any requests to URLs such as /products, will go to Spree::ProductsController.
# If you would like to change where this engine is mounted, simply change the :at option to something different.
#
# We ask that you don't use the :as option here, as Solidus relies on it being the default of "spree"
#{CORE_MOUNT_ROUTE}, at: '/'
ROUTES
end
end

unless options[:quiet]
puts "*" * 50
puts "We added the following line to your application's config/routes.rb file:"
puts " "
puts " #{CORE_MOUNT_ROUTE}, at: '/'"
end
end
end

0 comments on commit 819066b

Please sign in to comment.