将 Alchemy CMS 添加到 Spree 项目后没有路由工作
No routes work after adding Alchemy CMS to Spree project
我将 Alchemy CMS 添加到之前运行正常的 Spree 项目中。但是现在 none 的路线有效。对于所有路线,我得到一个页面 not found error
。我已经完成安装和 运行 所有迁移。
错误
Alchemy::Page not found "/"
宝石文件
ruby '2.2.4'
source 'https://rubygems.org'
gem 'rails', '4.2.5'
gem 'pg', '~> 0.15'
gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'active_model_serializers'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'spree', github: 'spree/spree', branch: 'master'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise'
gem 'puma'
gem 'paperclip'
gem 'aws-sdk', '< 2.0'
gem 'delayed_job_active_record'
gem 'alchemy_spree', github: 'magiclabs/alchemy_spree', branch: 'master'
# gem 'alchemy_cms', github: 'AlchemyCMS/alchemy_cms', branch: '3.1-stable'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
gem 'byebug'
end
group :development do
gem 'web-console', '~> 2.0'
gem 'spring'
end
config/routes.rb
Rails.application.routes.draw do
mount Alchemy::Engine => '/'
mount Spree::Core::Engine, :at => '/shop'
end
config/initializer/alchemy.rb
# Tell Alchemy to use the Spree::User class
Alchemy.user_class_name = 'Spree::User'
Alchemy.current_user_method = :spree_current_user
# Load the Spree.user_class decorator for Alchemy roles
require 'alchemy/spree/spree_user_decorator'
# Include the Spree controller helpers to render the
# alchemy pages within the default Spree layout
Alchemy::BaseHelper.send :include, Spree::BaseHelper
Alchemy::BaseController.send :include, Spree::Core::ControllerHelpers::Common
Alchemy::BaseController.send :include, Spree::Core::ControllerHelpers::Store
config/application.rb
module DistinctExistence
class Application < Rails::Application
config.to_prepare do
# Load application's model / class decorators
Dir.glob(File.join(File.dirname(__FILE__), '../app/**/*_decorator*.rb')) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
# Load application's view overrides
Dir.glob(File.join(File.dirname(__FILE__), '../app/overrides/*.rb')) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
Spree::UserSessionsController.class_eval do
include Alchemy::ControllerActions
end
end
config.time_zone = 'Central Time (US & Canada)'
config.active_job.queue_adapter = :delayed_job
config.active_record.raise_in_transactional_callbacks = true
end
end
config/initializers/spree.rb
Spree.config do |config|
# Example:
# Uncomment to stop tracking inventory levels in the application
# config.track_inventory_levels = false
end
Spree.user_class = 'Spree::User'
attachment_config = {
s3_credentials: {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
bucket: ENV['S3_BUCKET_NAME']
},
storage: :s3,
s3_headers: { 'Cache-Control' => 'max-age=31557600' },
s3_protocol: 'https',
bucket: ENV['S3_BUCKET_NAME'],
url: ':s3_domain_url',
styles: {
mini: '48x48>',
small: '100x100>',
product: '240x240>',
large: '600x600>'
},
path: '/:class/:id/:style/:basename.:extension',
default_url: '/:class/:id/:style/:basename.:extension',
default_style: 'product'
}
attachment_config.each do |key, value|
Spree::Image.attachment_definitions[:attachment][key.to_sym] = value
end
config/alchemy/element.yml
- name: article
hint: true
unique: true
contents:
- name: headline
type: EssenceText
default: :article_headline
hint: true
- name: picture
type: EssencePicture
hint: true
- name: text
type: EssenceRichtext
default: :article_text
hint: true
- name: product
contents:
- name: spree_product
type: EssenceSpreeProduct
- name: product_category
contents:
- name: spree_taxon
type: EssenceSpreeTaxon
config/alchemy.page_layouts.yml
- name: index
unique: true
elements: [article]
autogenerate: [article]
- name: product
elements: [product]
- name: products
elements: [product_category]
Alchemy 有很强的catch all 路线。请将 Alchemy 挂载为路由文件中的最后一个引擎:
Rails.application.routes.draw do
mount Spree::Core::Engine, :at => '/shop'
mount Alchemy::Engine => '/'
end
然后每个特定引擎的所有路由都可以在其路由前缀下访问。
因此,要访问 Spree 管理员,您需要使用 /shop/admin
,而炼金术路线都可以直接在 /
.
下访问
注意:要使重定向到登录路径有效,您需要将此告知 Alchemy。按照上面的示例,如果您使用 spree_auth_devise
:
# config/initializers/alchemy.rb
Alchemy.login_path = '/shop/login'
或者,如果您使用自己的自定义身份验证:
# config/initializers/alchemy.rb
Alchemy.login_path = '/sessions/new'
我将 Alchemy CMS 添加到之前运行正常的 Spree 项目中。但是现在 none 的路线有效。对于所有路线,我得到一个页面 not found error
。我已经完成安装和 运行 所有迁移。
错误
Alchemy::Page not found "/"
宝石文件
ruby '2.2.4'
source 'https://rubygems.org'
gem 'rails', '4.2.5'
gem 'pg', '~> 0.15'
gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'active_model_serializers'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'spree', github: 'spree/spree', branch: 'master'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise'
gem 'puma'
gem 'paperclip'
gem 'aws-sdk', '< 2.0'
gem 'delayed_job_active_record'
gem 'alchemy_spree', github: 'magiclabs/alchemy_spree', branch: 'master'
# gem 'alchemy_cms', github: 'AlchemyCMS/alchemy_cms', branch: '3.1-stable'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
gem 'byebug'
end
group :development do
gem 'web-console', '~> 2.0'
gem 'spring'
end
config/routes.rb
Rails.application.routes.draw do
mount Alchemy::Engine => '/'
mount Spree::Core::Engine, :at => '/shop'
end
config/initializer/alchemy.rb
# Tell Alchemy to use the Spree::User class
Alchemy.user_class_name = 'Spree::User'
Alchemy.current_user_method = :spree_current_user
# Load the Spree.user_class decorator for Alchemy roles
require 'alchemy/spree/spree_user_decorator'
# Include the Spree controller helpers to render the
# alchemy pages within the default Spree layout
Alchemy::BaseHelper.send :include, Spree::BaseHelper
Alchemy::BaseController.send :include, Spree::Core::ControllerHelpers::Common
Alchemy::BaseController.send :include, Spree::Core::ControllerHelpers::Store
config/application.rb
module DistinctExistence
class Application < Rails::Application
config.to_prepare do
# Load application's model / class decorators
Dir.glob(File.join(File.dirname(__FILE__), '../app/**/*_decorator*.rb')) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
# Load application's view overrides
Dir.glob(File.join(File.dirname(__FILE__), '../app/overrides/*.rb')) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
Spree::UserSessionsController.class_eval do
include Alchemy::ControllerActions
end
end
config.time_zone = 'Central Time (US & Canada)'
config.active_job.queue_adapter = :delayed_job
config.active_record.raise_in_transactional_callbacks = true
end
end
config/initializers/spree.rb
Spree.config do |config|
# Example:
# Uncomment to stop tracking inventory levels in the application
# config.track_inventory_levels = false
end
Spree.user_class = 'Spree::User'
attachment_config = {
s3_credentials: {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
bucket: ENV['S3_BUCKET_NAME']
},
storage: :s3,
s3_headers: { 'Cache-Control' => 'max-age=31557600' },
s3_protocol: 'https',
bucket: ENV['S3_BUCKET_NAME'],
url: ':s3_domain_url',
styles: {
mini: '48x48>',
small: '100x100>',
product: '240x240>',
large: '600x600>'
},
path: '/:class/:id/:style/:basename.:extension',
default_url: '/:class/:id/:style/:basename.:extension',
default_style: 'product'
}
attachment_config.each do |key, value|
Spree::Image.attachment_definitions[:attachment][key.to_sym] = value
end
config/alchemy/element.yml
- name: article
hint: true
unique: true
contents:
- name: headline
type: EssenceText
default: :article_headline
hint: true
- name: picture
type: EssencePicture
hint: true
- name: text
type: EssenceRichtext
default: :article_text
hint: true
- name: product
contents:
- name: spree_product
type: EssenceSpreeProduct
- name: product_category
contents:
- name: spree_taxon
type: EssenceSpreeTaxon
config/alchemy.page_layouts.yml
- name: index
unique: true
elements: [article]
autogenerate: [article]
- name: product
elements: [product]
- name: products
elements: [product_category]
Alchemy 有很强的catch all 路线。请将 Alchemy 挂载为路由文件中的最后一个引擎:
Rails.application.routes.draw do
mount Spree::Core::Engine, :at => '/shop'
mount Alchemy::Engine => '/'
end
然后每个特定引擎的所有路由都可以在其路由前缀下访问。
因此,要访问 Spree 管理员,您需要使用 /shop/admin
,而炼金术路线都可以直接在 /
.
注意:要使重定向到登录路径有效,您需要将此告知 Alchemy。按照上面的示例,如果您使用 spree_auth_devise
:
# config/initializers/alchemy.rb
Alchemy.login_path = '/shop/login'
或者,如果您使用自己的自定义身份验证:
# config/initializers/alchemy.rb
Alchemy.login_path = '/sessions/new'