将 Alchemy CMS 添加到 Spree 项目后,路由不起作用

问题描述 投票:0回答:2

我将 Alchemy CMS 添加到了之前运行正常的 Spree 项目中。但现在所有路线都不起作用了。对于所有路线,我都会得到一个页面

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

配置/routes.rb

Rails.application.routes.draw do
  mount Alchemy::Engine => '/'
  mount Spree::Core::Engine, :at => '/shop'
end

配置/初始化程序/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

配置/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

配置/初始化器/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]
ruby-on-rails spree alchemy-cms alchemy-spree
2个回答
1
投票

炼金术有很强的万能路线。请将 Alchemy 安装为路线文件中的最后一个引擎:

Rails.application.routes.draw do
  mount Spree::Core::Engine, :at => '/shop'
  mount Alchemy::Engine => '/'
end

然后每个特定引擎的所有路由都可以在其路由前缀下访问。

因此,要访问 Spree 管理员,您需要使用

/shop/admin
,而 Alchemy 路线都可以直接在
/
下访问。

注意:要使重定向到登录路径起作用,您需要告诉 Alchemy 这一点。按照上面的示例,如果您使用

spree_auth_devise
:

# config/initializers/alchemy.rb
Alchemy.login_path = '/shop/login'

或者,如果您使用自己的自定义身份验证:

# config/initializers/alchemy.rb
Alchemy.login_path = '/sessions/new'

0
投票

您始终可以在像initializers/mixins.rb这样的文件中对路由进行猴子修补:

class ActionView::Base
  def page_path(page)
    "/page/#{page.id}"
  end

  def login_path
    "/login"
  end
end
© www.soinside.com 2019 - 2024. All rights reserved.