簡體   English   中英

服務器啟動后,Ruby on Rails將不會注冊active_admin(http:// localhost:3001 / admin)

[英]Ruby on Rails will not register active_admin upon server startup (http://localhost:3001/admin)

我目前正在創建我的第一個Rail-on-Rails項目。 我在嘗試運行RoR api時加載服務器時遇到問題。

Application.rb

    require_relative 'boot'

    require "rails"
    # Pick the frameworks you want:
    require "active_model/railtie"
    require "active_job/railtie"
    require "active_record/railtie"
    require "active_storage/engine"
    require "action_controller/railtie"
    require "action_mailer/railtie"
    require "action_view/railtie"
    require "action_cable/engine"
    require "sprockets/railtie"
    require "rails/test_unit/railtie"

    # Require the gems listed in Gemfile, including any gems
    # you've limited to :test, :development, or :production.
    Bundler.require(*Rails.groups)

    module ListOfIngredients
    class Application < Rails::Application
    # Initialize configuration defaults for originally generated 
    Rails version.
    config.load_defaults 5.2

    # Settings in config/environments/* take precedence over those 
    specified here.
    # Application configuration can go into files in 
    config/initializers
    # -- all .rb files in that directory are automatically loaded 
    after loading
    # the framework and any gems in your application.

    # Only loads a smaller set of middleware suitable for API only 
    apps.
    # Middleware like session, flash, cookies can be added back 
    manually.
    # Skip views, helpers and assets when generating a new resource.
    config.api_only = true

    # Middleware for ActiveAdmin
    config.middleware.use Rack::MethodOverride
    config.middleware.use ActionDispatch::Flash
    config.middleware.use ActionDispatch::Cookies
    config.middleware.use ActionDispatch::Session::CookieStore
    end
    end

寶石文件。

   source 'https://rubygems.org'
   git_source(:github) { |repo| "https://github.com/#{repo}.git" }

   ruby '2.5.1'

   # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
   gem 'rails', '~> 5.2.0'
   # Use Puma as the app server
   gem 'puma', '~> 3.11'
   # Build JSON APIs with ease. Read more: 
   https://github.com/rails/jbuilder
   # gem 'jbuilder', '~> 2.5'
   # Use Redis adapter to run Action Cable in production
   # gem 'redis', '~> 4.0'
   # Use ActiveModel has_secure_password
   # gem 'bcrypt', '~> 3.1.7'

   # Use ActiveStorage variant
   # gem 'mini_magick', '~> 4.8'

   # Use Capistrano for deployment
   # gem 'capistrano-rails', group: :development

   # Reduces boot times through caching; required in config/boot.rb
   gem 'bootsnap', '>= 1.1.0', require: false

   # Use Rack CORS for handling Cross-Origin Resource Sharing 
   (CORS), making cross-origin AJAX possible
   # gem 'rack-cors'

   group :development, :test do
   # Use sqlite3 as the database for Active Record
   gem 'sqlite3'
   # Call 'byebug' anywhere in the code to stop execution and get a 
   debugger console
   gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
   end

   group :development do
   gem 'listen', '>= 3.0.5', '< 3.2'
   # Spring speeds up development by keeping your application 
   running in the background. Read more: 
   https://github.com/rails/spring
   gem 'spring'
   gem 'spring-watcher-listen', '~> 2.0.0'
   end

   group :production do
   # Use postgres as the database for production
   gem 'pg'
   end

   # ActiveAdmin
   gem 'devise'
   gem 'activeadmin'

   # Windows does not include zoneinfo files, so bundle the tzinfo- 
   data gem
   gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, 
   :jruby]

我還設置了兩個控制器,如下所示。

api_controller.rb

   class ApiController < ActionController::API
   end

application_controller.rb

    class ApplicationController < ActionController::Base
      protect_from_forgery with: :exception
    end

當我在localhost 3001上運行rails時,仍然會以錯誤消息結束。

在ActiveAdmin :: Devise :: Sessions#new中的Sprockets :: Rails :: Helper :: AssetNotFound

Rails 5 API不包含資產文件夾時,活動管理員資產應該去哪里?

我很確定ActiveAdmin需要鏈輪。 你跑了嗎

rails generate devise:install

您可能還需要運行

rails generate devise:views

有關競爭的更多信息,請參見devise Wiki。

也許看看這個答案這個 答案

更新:

如果您按照本教程中的說明進行操作,則可能想在application.rb中注釋掉這一行

# require "sprockets/railtie"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM