ruby-on-rails 添加Alchemy CMS到Spree项目后没有路由工作

pcww981p  于 2023-10-21  发布在  Ruby
关注(0)|答案(2)|浏览(116)

我添加了炼金术CMS到我的狂欢项目,以前运行正常。但现在所有的路线都不起作用了。对于所有的路由,我得到一个页面not found error。我已经完成了安装并运行了所有的迁移。

错误

Alchemy::Page not found "/"

Gemfile

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]
ercv8c1e

ercv8c1e1#

炼金术有一个非常强大的捕捉所有路线。请将Alchemy挂载为路由文件中的最后一个引擎:

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

然后,每个特定引擎的所有路由都可以在其路由前缀下访问。
因此,要访问Spree admin,您需要使用/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'
vyu0f0g1

vyu0f0g12#

你可以在初始化器/mixins.rb这样的文件中加入路由补丁:

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

  def login_path
    "/login"
  end
end

相关问题