Ruby on rails 如何让rails 4类别显示在我的rails应用程序上?

Ruby on rails 如何让rails 4类别显示在我的rails应用程序上?,ruby-on-rails,activerecord,ruby-on-rails-4,activeadmin,Ruby On Rails,Activerecord,Ruby On Rails 4,Activeadmin,我正在尝试使用HABTM方法向rails中的事件添加类别。由于某种原因,它根本不起作用。另外,active admin中的my id字段用my event的标题填充,而不是像这样的id整数:/admin/events/event test 我有以下设置: model/event.rb class Event < ActiveRecord::Base has_and_belongs_to_many :categories self.primary_key = :id

我正在尝试使用HABTM方法向rails中的事件添加类别。由于某种原因,它根本不起作用。另外,active admin中的my id字段用my event的标题填充,而不是像这样的id整数:
/admin/events/event test

我有以下设置:

model/event.rb

class Event < ActiveRecord::Base
    has_and_belongs_to_many :categories 
    self.primary_key = :id
    has_attached_file :event_image, styles: {
        large: "600x450#",
        medium: "250x250#",
        small: "100x100#"
    }, :default_url => "/images/:style/filler.png"
    validates :title, :slug, :event_image, presence: true   
    extend FriendlyId
    friendly_id :title, use: :slugged
end
model/category.rb

class Category < ActiveRecord::Base
    has_and_belongs_to_many :events
    self.primary_key = :id
end
ActiveAdmin.register Category do
    controller do
       def permitted_params
          params.permit category: [:id]
       end
       def find_resource
            scoped_collection.friendly.find(params[:name])
        end
    end
    form do |f|
      f.inputs "Details" do
        f.input :name
      end
      f.actions
    end
end
schema.rb

  create_table "categories", id: false, force: true do |t|
    t.integer  "id"
    t.string   "name"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "categories_events", force: true do |t|
    t.integer "category_id"
    t.integer "event_id"
  end
事件\u控制器.rb

class EventsController < InheritedResources::Base

    def index
        @events = Event.all
    end

    def show
        @event = Event.friendly.find(params[:id])
    end

end
class CategoriesController < InheritedResources::Base

    def index
        @categories = Category.all
    end
    def show
        @category = Category.find(params[:id])
    end

end
class EventsController
类别(u controller.rb)

class EventsController < InheritedResources::Base

    def index
        @events = Event.all
    end

    def show
        @event = Event.friendly.find(params[:id])
    end

end
class CategoriesController < InheritedResources::Base

    def index
        @categories = Category.all
    end
    def show
        @category = Category.find(params[:id])
    end

end
class CategoriesController
当我转到我的视图并尝试访问所选类别时,我得到[]


有人知道这里可能存在什么问题吗?

看起来是一个参数很强的问题。我如何克服这个问题(只是一个旁注,但你为什么这么做:self.primary_key=:idrails4guides.com:因为它不允许我在我的事件页面上显示我的类别下拉列表。)