Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails/ActiveAdmin关联错误-没有路由匹配…;缺少必需的密钥:[:类别\u id]_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails Rails/ActiveAdmin关联错误-没有路由匹配…;缺少必需的密钥:[:类别\u id]

Ruby on rails Rails/ActiveAdmin关联错误-没有路由匹配…;缺少必需的密钥:[:类别\u id],ruby-on-rails,ruby,Ruby On Rails,Ruby,我是Rails的新手,遇到了一个问题,如果有人能简单地解释一下我做错了什么,我会非常感激。在这里看了很多类似的问题后,我无法确定我的错误发生在流程的哪一部分 我有一个非常基本的网站,运行非常好,我添加了ActiveAdmin。一切都好。在那一点上,我决定引入一种类别形式的关系。以前,用户可以有多种状态。更改后: 一个用户可以有多种状态 状态将属于一个类别 一个类别可以与许多状态相关联 类别可以通过管理面板进行管理 无法通过公共站点直接管理类别 这就是我打碎东西的地方。该网站的公共部分仍然允许

我是Rails的新手,遇到了一个问题,如果有人能简单地解释一下我做错了什么,我会非常感激。在这里看了很多类似的问题后,我无法确定我的错误发生在流程的哪一部分

我有一个非常基本的网站,运行非常好,我添加了ActiveAdmin。一切都好。在那一点上,我决定引入一种类别形式的关系。以前,用户可以有多种状态。更改后:

  • 一个用户可以有多种状态
  • 状态将属于一个类别
  • 一个类别可以与许多状态相关联
  • 类别可以通过管理面板进行管理
  • 无法通过公共站点直接管理类别
这就是我打碎东西的地方。该网站的公共部分仍然允许我在状态上进行CRUD操作,这是绝对正确的。但是,由于该错误,我现在无法访问任何ActiveAdmin页面,该错误是在我尝试将状态与类别关联后才引入的

如果有人能为我指出问题的方向,或提供任何额外的阅读资料,我将不胜感激。先谢谢你

完全错误

返回

schema.rb

ActiveRecord::Schema.define(version: 20170107060018) do

  create_table "active_admin_comments", force: true do |t|
    t.string   "namespace"
    t.text     "body"
    t.string   "resource_id",   null: false
    t.string   "resource_type", null: false
    t.integer  "author_id"
    t.string   "author_type"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "active_admin_comments", ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"
  add_index "active_admin_comments", ["namespace"], name: "index_active_admin_comments_on_namespace"
  add_index "active_admin_comments", ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id"

  create_table "admin_users", force: true do |t|
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true
  add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true

  create_table "categories", force: true do |t|
    t.string "cat_name", null: false
  end

  create_table "statuses", force: true do |t|
    t.text     "content"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "user_id"
    t.boolean  "private",     default: false
    t.integer  "category_id"
  end

  add_index "statuses", ["category_id"], name: "index_statuses_on_category_id"
  add_index "statuses", ["user_id"], name: "index_statuses_on_user_id"

  create_table "users", force: true do |t|
    t.string   "first_name"
    t.string   "last_name"
    t.string   "profile_name"
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "provider"
    t.string   "uid"
  end

  add_index "users", ["email"], name: "index_users_on_email", unique: true
  add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

end
Rails.application.routes.draw do

  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
  get '/dashboard', to: 'profiles#dashboard', as: :dashboard

  get 'profiles/show'

  get '/home', to: 'pages#home', as: :homepage
  get '/about', to: 'pages#about', as: :aboutpage
  get '/credits', to: 'pages#credits', as: :creditspage

  devise_for :users, :controllers => {:registrations => "users/registrations"}

  devise_scope :user do
    get 'register', to: 'devise/registrations#new', as: :register
    get 'login', to: 'devise/sessions#new', as: :login
    get 'logout', to: 'devise/sessions#destroy', as: :logout
  end 

  resources :statuses

  get 'feed', to: 'statuses#index', as: :feed
  root to: 'pages#home' #Nothing in the path - index

  get '/:id', to: 'profiles#show'
end
class StatusesController < ApplicationController
  before_filter :authenticate_user!, only: [:new, :create, :edit, :update]
  before_action :set_status, only: [:show, :edit, :update, :destroy]
  before_action :correct_user,   only: [:destroy, :edit]

  def index
    @statuses = Status.paginate(page: params[:page], per_page: 50).order('created_at DESC')
  end

  def show
    if can? :read, @status
      render action: :show
    else
      render file: 'public/pleaseregister'
    end
  end

  def new
    @status = Status.new
  end

  def edit
  end

  def create
    @user = current_user
    @status = @user.statuses.build(status_params)

    respond_to do |format|
      if @status.save
        format.html { redirect_to @status, notice: 'Status was successfully created.' }
        format.json { render :show, status: :created, location: @status }
      else
        format.html { render :new }
        format.json { render json: @status.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    if can? :update, @status
    respond_to do |format|

        if @status.update(status_params)

          format.html { redirect_to @status, notice: 'Status was successfully updated.' }
          format.json { render :show, status: :ok, location: @status }
        else
          format.html { render :edit }
          format.json { render json: @status.errors, status: :unprocessable_entity }
        end

    end
    end
  end

  def destroy
    if can? :delete, @status
      @status.destroy
      respond_to do |format|

          format.html { redirect_to statuses_url, notice: 'Status was successfully destroyed.' }
          format.json { head :no_content }
      end
    end
  end


  private
    def set_status
      @status = Status.find(params[:id])
    end

    def status_params
      params.require(:status).permit(:name, :content, :user_id, :private, :category_id)
    end

    def correct_user
      @status = current_user.statuses.find_by(id: params[:id])
      redirect_to root_url if @status.nil?
    end
end
class CategoriesController < ApplicationController

end
ActiveAdmin.register Status do

    permit_params :user_id, :content, :private, :category_id
    belongs_to :user
    belongs_to :category
    menu priority: 4

end
ActiveAdmin.register Category do

    permit_params :cat_name
    has_many :statuses
    menu priority: 5

end
routes.rb

ActiveRecord::Schema.define(version: 20170107060018) do

  create_table "active_admin_comments", force: true do |t|
    t.string   "namespace"
    t.text     "body"
    t.string   "resource_id",   null: false
    t.string   "resource_type", null: false
    t.integer  "author_id"
    t.string   "author_type"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "active_admin_comments", ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"
  add_index "active_admin_comments", ["namespace"], name: "index_active_admin_comments_on_namespace"
  add_index "active_admin_comments", ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id"

  create_table "admin_users", force: true do |t|
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true
  add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true

  create_table "categories", force: true do |t|
    t.string "cat_name", null: false
  end

  create_table "statuses", force: true do |t|
    t.text     "content"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "user_id"
    t.boolean  "private",     default: false
    t.integer  "category_id"
  end

  add_index "statuses", ["category_id"], name: "index_statuses_on_category_id"
  add_index "statuses", ["user_id"], name: "index_statuses_on_user_id"

  create_table "users", force: true do |t|
    t.string   "first_name"
    t.string   "last_name"
    t.string   "profile_name"
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "provider"
    t.string   "uid"
  end

  add_index "users", ["email"], name: "index_users_on_email", unique: true
  add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

end
Rails.application.routes.draw do

  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
  get '/dashboard', to: 'profiles#dashboard', as: :dashboard

  get 'profiles/show'

  get '/home', to: 'pages#home', as: :homepage
  get '/about', to: 'pages#about', as: :aboutpage
  get '/credits', to: 'pages#credits', as: :creditspage

  devise_for :users, :controllers => {:registrations => "users/registrations"}

  devise_scope :user do
    get 'register', to: 'devise/registrations#new', as: :register
    get 'login', to: 'devise/sessions#new', as: :login
    get 'logout', to: 'devise/sessions#destroy', as: :logout
  end 

  resources :statuses

  get 'feed', to: 'statuses#index', as: :feed
  root to: 'pages#home' #Nothing in the path - index

  get '/:id', to: 'profiles#show'
end
class StatusesController < ApplicationController
  before_filter :authenticate_user!, only: [:new, :create, :edit, :update]
  before_action :set_status, only: [:show, :edit, :update, :destroy]
  before_action :correct_user,   only: [:destroy, :edit]

  def index
    @statuses = Status.paginate(page: params[:page], per_page: 50).order('created_at DESC')
  end

  def show
    if can? :read, @status
      render action: :show
    else
      render file: 'public/pleaseregister'
    end
  end

  def new
    @status = Status.new
  end

  def edit
  end

  def create
    @user = current_user
    @status = @user.statuses.build(status_params)

    respond_to do |format|
      if @status.save
        format.html { redirect_to @status, notice: 'Status was successfully created.' }
        format.json { render :show, status: :created, location: @status }
      else
        format.html { render :new }
        format.json { render json: @status.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    if can? :update, @status
    respond_to do |format|

        if @status.update(status_params)

          format.html { redirect_to @status, notice: 'Status was successfully updated.' }
          format.json { render :show, status: :ok, location: @status }
        else
          format.html { render :edit }
          format.json { render json: @status.errors, status: :unprocessable_entity }
        end

    end
    end
  end

  def destroy
    if can? :delete, @status
      @status.destroy
      respond_to do |format|

          format.html { redirect_to statuses_url, notice: 'Status was successfully destroyed.' }
          format.json { head :no_content }
      end
    end
  end


  private
    def set_status
      @status = Status.find(params[:id])
    end

    def status_params
      params.require(:status).permit(:name, :content, :user_id, :private, :category_id)
    end

    def correct_user
      @status = current_user.statuses.find_by(id: params[:id])
      redirect_to root_url if @status.nil?
    end
end
class CategoriesController < ApplicationController

end
ActiveAdmin.register Status do

    permit_params :user_id, :content, :private, :category_id
    belongs_to :user
    belongs_to :category
    menu priority: 4

end
ActiveAdmin.register Category do

    permit_params :cat_name
    has_many :statuses
    menu priority: 5

end
型号

class Category < ActiveRecord::Base
    has_many :statuses
end

class Status < ActiveRecord::Base
    belongs_to :user
    belongs_to :category

    validates :content, presence: true, length: {minimum: 2}
    validates :user_id, presence: true
end
Prefix Verb       URI Pattern                                                    Controller#Action
              new_admin_user_session GET        /admin/login(.:format)                                         active_admin/devise/sessions#new
                  admin_user_session POST       /admin/login(.:format)                                         active_admin/devise/sessions#create
          destroy_admin_user_session DELETE|GET /admin/logout(.:format)                                        active_admin/devise/sessions#destroy
                 admin_user_password POST       /admin/password(.:format)                                      active_admin/devise/passwords#create
             new_admin_user_password GET        /admin/password/new(.:format)                                  active_admin/devise/passwords#new
            edit_admin_user_password GET        /admin/password/edit(.:format)                                 active_admin/devise/passwords#edit
                                     PATCH      /admin/password(.:format)                                      active_admin/devise/passwords#update
                                     PUT        /admin/password(.:format)                                      active_admin/devise/passwords#update
                          admin_root GET        /admin(.:format)                                               admin/dashboard#index
      batch_action_admin_admin_users POST       /admin/admin_users/batch_action(.:format)                      admin/admin_users#batch_action
                   admin_admin_users GET        /admin/admin_users(.:format)                                   admin/admin_users#index
                                     POST       /admin/admin_users(.:format)                                   admin/admin_users#create
                new_admin_admin_user GET        /admin/admin_users/new(.:format)                               admin/admin_users#new
               edit_admin_admin_user GET        /admin/admin_users/:id/edit(.:format)                          admin/admin_users#edit
                    admin_admin_user GET        /admin/admin_users/:id(.:format)                               admin/admin_users#show
                                     PATCH      /admin/admin_users/:id(.:format)                               admin/admin_users#update
                                     PUT        /admin/admin_users/:id(.:format)                               admin/admin_users#update
                                     DELETE     /admin/admin_users/:id(.:format)                               admin/admin_users#destroy
       batch_action_admin_categories POST       /admin/categories/batch_action(.:format)                       admin/categories#batch_action
                    admin_categories GET        /admin/categories(.:format)                                    admin/categories#index
                                     POST       /admin/categories(.:format)                                    admin/categories#create
                  new_admin_category GET        /admin/categories/new(.:format)                                admin/categories#new
                 edit_admin_category GET        /admin/categories/:id/edit(.:format)                           admin/categories#edit
                      admin_category GET        /admin/categories/:id(.:format)                                admin/categories#show
                                     PATCH      /admin/categories/:id(.:format)                                admin/categories#update
                                     PUT        /admin/categories/:id(.:format)                                admin/categories#update
                                     DELETE     /admin/categories/:id(.:format)                                admin/categories#destroy
                     admin_dashboard GET        /admin/dashboard(.:format)                                     admin/dashboard#index
batch_action_admin_category_statuses POST       /admin/categories/:category_id/statuses/batch_action(.:format) admin/statuses#batch_action
             admin_category_statuses GET        /admin/categories/:category_id/statuses(.:format)              admin/statuses#index
                                     POST       /admin/categories/:category_id/statuses(.:format)              admin/statuses#create
           new_admin_category_status GET        /admin/categories/:category_id/statuses/new(.:format)          admin/statuses#new
          edit_admin_category_status GET        /admin/categories/:category_id/statuses/:id/edit(.:format)     admin/statuses#edit
               admin_category_status GET        /admin/categories/:category_id/statuses/:id(.:format)          admin/statuses#show
                                     PATCH      /admin/categories/:category_id/statuses/:id(.:format)          admin/statuses#update
                                     PUT        /admin/categories/:category_id/statuses/:id(.:format)          admin/statuses#update
                                     DELETE     /admin/categories/:category_id/statuses/:id(.:format)          admin/statuses#destroy
            batch_action_admin_users POST       /admin/users/batch_action(.:format)                            admin/users#batch_action
                         admin_users GET        /admin/users(.:format)                                         admin/users#index
                                     POST       /admin/users(.:format)                                         admin/users#create
                      new_admin_user GET        /admin/users/new(.:format)                                     admin/users#new
                     edit_admin_user GET        /admin/users/:id/edit(.:format)                                admin/users#edit
                          admin_user GET        /admin/users/:id(.:format)                                     admin/users#show
                                     PATCH      /admin/users/:id(.:format)                                     admin/users#update
                                     PUT        /admin/users/:id(.:format)                                     admin/users#update
                                     DELETE     /admin/users/:id(.:format)                                     admin/users#destroy
                      admin_comments GET        /admin/comments(.:format)                                      admin/comments#index
                                     POST       /admin/comments(.:format)                                      admin/comments#create
                       admin_comment GET        /admin/comments/:id(.:format)                                  admin/comments#show
                                     DELETE     /admin/comments/:id(.:format)                                  admin/comments#destroy
                           dashboard GET        /dashboard(.:format)                                           profiles#dashboard
                       profiles_show GET        /profiles/show(.:format)                                       profiles#show
                            homepage GET        /home(.:format)                                                pages#home
                           aboutpage GET        /about(.:format)                                               pages#about
                         creditspage GET        /credits(.:format)                                             pages#credits
                    new_user_session GET        /users/sign_in(.:format)                                       devise/sessions#new
                        user_session POST       /users/sign_in(.:format)                                       devise/sessions#create
                destroy_user_session DELETE     /users/sign_out(.:format)                                      devise/sessions#destroy
                       user_password POST       /users/password(.:format)                                      devise/passwords#create
                   new_user_password GET        /users/password/new(.:format)                                  devise/passwords#new
                  edit_user_password GET        /users/password/edit(.:format)                                 devise/passwords#edit
                                     PATCH      /users/password(.:format)                                      devise/passwords#update
                                     PUT        /users/password(.:format)                                      devise/passwords#update
            cancel_user_registration GET        /users/cancel(.:format)                                        users/registrations#cancel
                   user_registration POST       /users(.:format)                                               users/registrations#create
               new_user_registration GET        /users/sign_up(.:format)                                       users/registrations#new
              edit_user_registration GET        /users/edit(.:format)                                          users/registrations#edit
                                     PATCH      /users(.:format)                                               users/registrations#update
                                     PUT        /users(.:format)                                               users/registrations#update
                                     DELETE     /users(.:format)                                               users/registrations#destroy
                            register GET        /register(.:format)                                            devise/registrations#new
                               login GET        /login(.:format)                                               devise/sessions#new
                              logout GET        /logout(.:format)                                              devise/sessions#destroy
                            statuses GET        /statuses(.:format)                                            statuses#index
                                     POST       /statuses(.:format)                                            statuses#create
                          new_status GET        /statuses/new(.:format)                                        statuses#new
                         edit_status GET        /statuses/:id/edit(.:format)                                   statuses#edit
                              status GET        /statuses/:id(.:format)                                        statuses#show
                                     PATCH      /statuses/:id(.:format)                                        statuses#update
                                     PUT        /statuses/:id(.:format)                                        statuses#update
                                     DELETE     /statuses/:id(.:format)                                        statuses#destroy
                                feed GET        /feed(.:format)                                                statuses#index
                                root GET        /                                                              pages#home
                                     GET        /:id(.:format)                                                 profiles#show
app/admin/status.rb

ActiveRecord::Schema.define(version: 20170107060018) do

  create_table "active_admin_comments", force: true do |t|
    t.string   "namespace"
    t.text     "body"
    t.string   "resource_id",   null: false
    t.string   "resource_type", null: false
    t.integer  "author_id"
    t.string   "author_type"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "active_admin_comments", ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"
  add_index "active_admin_comments", ["namespace"], name: "index_active_admin_comments_on_namespace"
  add_index "active_admin_comments", ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id"

  create_table "admin_users", force: true do |t|
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true
  add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true

  create_table "categories", force: true do |t|
    t.string "cat_name", null: false
  end

  create_table "statuses", force: true do |t|
    t.text     "content"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "user_id"
    t.boolean  "private",     default: false
    t.integer  "category_id"
  end

  add_index "statuses", ["category_id"], name: "index_statuses_on_category_id"
  add_index "statuses", ["user_id"], name: "index_statuses_on_user_id"

  create_table "users", force: true do |t|
    t.string   "first_name"
    t.string   "last_name"
    t.string   "profile_name"
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "provider"
    t.string   "uid"
  end

  add_index "users", ["email"], name: "index_users_on_email", unique: true
  add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

end
Rails.application.routes.draw do

  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
  get '/dashboard', to: 'profiles#dashboard', as: :dashboard

  get 'profiles/show'

  get '/home', to: 'pages#home', as: :homepage
  get '/about', to: 'pages#about', as: :aboutpage
  get '/credits', to: 'pages#credits', as: :creditspage

  devise_for :users, :controllers => {:registrations => "users/registrations"}

  devise_scope :user do
    get 'register', to: 'devise/registrations#new', as: :register
    get 'login', to: 'devise/sessions#new', as: :login
    get 'logout', to: 'devise/sessions#destroy', as: :logout
  end 

  resources :statuses

  get 'feed', to: 'statuses#index', as: :feed
  root to: 'pages#home' #Nothing in the path - index

  get '/:id', to: 'profiles#show'
end
class StatusesController < ApplicationController
  before_filter :authenticate_user!, only: [:new, :create, :edit, :update]
  before_action :set_status, only: [:show, :edit, :update, :destroy]
  before_action :correct_user,   only: [:destroy, :edit]

  def index
    @statuses = Status.paginate(page: params[:page], per_page: 50).order('created_at DESC')
  end

  def show
    if can? :read, @status
      render action: :show
    else
      render file: 'public/pleaseregister'
    end
  end

  def new
    @status = Status.new
  end

  def edit
  end

  def create
    @user = current_user
    @status = @user.statuses.build(status_params)

    respond_to do |format|
      if @status.save
        format.html { redirect_to @status, notice: 'Status was successfully created.' }
        format.json { render :show, status: :created, location: @status }
      else
        format.html { render :new }
        format.json { render json: @status.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    if can? :update, @status
    respond_to do |format|

        if @status.update(status_params)

          format.html { redirect_to @status, notice: 'Status was successfully updated.' }
          format.json { render :show, status: :ok, location: @status }
        else
          format.html { render :edit }
          format.json { render json: @status.errors, status: :unprocessable_entity }
        end

    end
    end
  end

  def destroy
    if can? :delete, @status
      @status.destroy
      respond_to do |format|

          format.html { redirect_to statuses_url, notice: 'Status was successfully destroyed.' }
          format.json { head :no_content }
      end
    end
  end


  private
    def set_status
      @status = Status.find(params[:id])
    end

    def status_params
      params.require(:status).permit(:name, :content, :user_id, :private, :category_id)
    end

    def correct_user
      @status = current_user.statuses.find_by(id: params[:id])
      redirect_to root_url if @status.nil?
    end
end
class CategoriesController < ApplicationController

end
ActiveAdmin.register Status do

    permit_params :user_id, :content, :private, :category_id
    belongs_to :user
    belongs_to :category
    menu priority: 4

end
ActiveAdmin.register Category do

    permit_params :cat_name
    has_many :statuses
    menu priority: 5

end
app/admin/category.rb

ActiveRecord::Schema.define(version: 20170107060018) do

  create_table "active_admin_comments", force: true do |t|
    t.string   "namespace"
    t.text     "body"
    t.string   "resource_id",   null: false
    t.string   "resource_type", null: false
    t.integer  "author_id"
    t.string   "author_type"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "active_admin_comments", ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"
  add_index "active_admin_comments", ["namespace"], name: "index_active_admin_comments_on_namespace"
  add_index "active_admin_comments", ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id"

  create_table "admin_users", force: true do |t|
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "admin_users", ["email"], name: "index_admin_users_on_email", unique: true
  add_index "admin_users", ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true

  create_table "categories", force: true do |t|
    t.string "cat_name", null: false
  end

  create_table "statuses", force: true do |t|
    t.text     "content"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "user_id"
    t.boolean  "private",     default: false
    t.integer  "category_id"
  end

  add_index "statuses", ["category_id"], name: "index_statuses_on_category_id"
  add_index "statuses", ["user_id"], name: "index_statuses_on_user_id"

  create_table "users", force: true do |t|
    t.string   "first_name"
    t.string   "last_name"
    t.string   "profile_name"
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "provider"
    t.string   "uid"
  end

  add_index "users", ["email"], name: "index_users_on_email", unique: true
  add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

end
Rails.application.routes.draw do

  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
  get '/dashboard', to: 'profiles#dashboard', as: :dashboard

  get 'profiles/show'

  get '/home', to: 'pages#home', as: :homepage
  get '/about', to: 'pages#about', as: :aboutpage
  get '/credits', to: 'pages#credits', as: :creditspage

  devise_for :users, :controllers => {:registrations => "users/registrations"}

  devise_scope :user do
    get 'register', to: 'devise/registrations#new', as: :register
    get 'login', to: 'devise/sessions#new', as: :login
    get 'logout', to: 'devise/sessions#destroy', as: :logout
  end 

  resources :statuses

  get 'feed', to: 'statuses#index', as: :feed
  root to: 'pages#home' #Nothing in the path - index

  get '/:id', to: 'profiles#show'
end
class StatusesController < ApplicationController
  before_filter :authenticate_user!, only: [:new, :create, :edit, :update]
  before_action :set_status, only: [:show, :edit, :update, :destroy]
  before_action :correct_user,   only: [:destroy, :edit]

  def index
    @statuses = Status.paginate(page: params[:page], per_page: 50).order('created_at DESC')
  end

  def show
    if can? :read, @status
      render action: :show
    else
      render file: 'public/pleaseregister'
    end
  end

  def new
    @status = Status.new
  end

  def edit
  end

  def create
    @user = current_user
    @status = @user.statuses.build(status_params)

    respond_to do |format|
      if @status.save
        format.html { redirect_to @status, notice: 'Status was successfully created.' }
        format.json { render :show, status: :created, location: @status }
      else
        format.html { render :new }
        format.json { render json: @status.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    if can? :update, @status
    respond_to do |format|

        if @status.update(status_params)

          format.html { redirect_to @status, notice: 'Status was successfully updated.' }
          format.json { render :show, status: :ok, location: @status }
        else
          format.html { render :edit }
          format.json { render json: @status.errors, status: :unprocessable_entity }
        end

    end
    end
  end

  def destroy
    if can? :delete, @status
      @status.destroy
      respond_to do |format|

          format.html { redirect_to statuses_url, notice: 'Status was successfully destroyed.' }
          format.json { head :no_content }
      end
    end
  end


  private
    def set_status
      @status = Status.find(params[:id])
    end

    def status_params
      params.require(:status).permit(:name, :content, :user_id, :private, :category_id)
    end

    def correct_user
      @status = current_user.statuses.find_by(id: params[:id])
      redirect_to root_url if @status.nil?
    end
end
class CategoriesController < ApplicationController

end
ActiveAdmin.register Status do

    permit_params :user_id, :content, :private, :category_id
    belongs_to :user
    belongs_to :category
    menu priority: 4

end
ActiveAdmin.register Category do

    permit_params :cat_name
    has_many :statuses
    menu priority: 5

end

可能在
app/views/active\u admin/page/index.html.arb
(也许你有菜单?)的某个地方,你正在构建一个指向/admin/statuses页面的链接(
admin\u category\u statuses\u path
),但你没有在其中提供category参数。

修复!问题出在admin目录中的rb文件中-我错误地试图在这里定义类别和状态之间的关系,我认为这是因为我误解了引用:@ruby_newbie you close,只是错误的文件,但它让我再次看到:)

ActiveAdmin中的关系仍然不太正确(过滤器显示的是对对象的引用,而不是名称等),但它正在再次加载,我将从这里开始


非常感谢您的所有建议,请发布
rake路线
output@BMxer感谢您的提示-现在添加。似乎路由正在解析为
admin\u category\u statuses GET/admin/categories/:category\u id/statuses(:format)管理员/状态#索引
和类别id缺失,这与错误消息相对应。但我不明白为什么访问:3000/admin会进入这条路径。如果你删除Status.rb中的这行:“属于:类别”,它会修复你的错误吗?@ruby\u新手恐怕不会,没有变化。