Ruby on rails 为什么在我提交表单时,我的类别选择框中的active admin中的新条目会显示“不能为空”?

Ruby on rails 为什么在我提交表单时,我的类别选择框中的active admin中的新条目会显示“不能为空”?,ruby-on-rails,ruby-on-rails-4,activeadmin,categories,Ruby On Rails,Ruby On Rails 4,Activeadmin,Categories,我正在Active Admin中创建一个配置文件区域。我创建了一个名为profile的scaffold,并使用继承的资源在后端为我创建了admin字段,这很好 我唯一的问题是当我添加详细信息并选择类别时,它表示类别不能为空。这令人困惑,因为它一点也不空白 以下是我的设置: app/admin/profile.rb ActiveAdmin.register Profile do controller do def permitted_params par

我正在Active Admin中创建一个配置文件区域。我创建了一个名为profile的scaffold,并使用继承的资源在后端为我创建了admin字段,这很好

我唯一的问题是当我添加详细信息并选择类别时,它表示类别不能为空。这令人困惑,因为它一点也不空白

以下是我的设置:

app/admin/profile.rb

ActiveAdmin.register Profile do

    controller do
       def permitted_params
          params.permit profile: [:name, :profile_image, :content]
       end
    end
    controller do
        def find_resource
            scoped_collection.friendly.find(params[:id])
        end
    end

end
class Profile < ActiveRecord::Base

    has_attached_file :profile_image, styles: {
        large: "600x450#",
        medium: "250x250#",
        small: "100x100#"
    }, :default_url => "/images/:style/filler.png"

    belongs_to :category
    validates :name, :profile_image, presence: true
    extend FriendlyId
    friendly_id :name, use: :slugged

    attr_accessor :slug

end
app/models/profile.rb

ActiveAdmin.register Profile do

    controller do
       def permitted_params
          params.permit profile: [:name, :profile_image, :content]
       end
    end
    controller do
        def find_resource
            scoped_collection.friendly.find(params[:id])
        end
    end

end
class Profile < ActiveRecord::Base

    has_attached_file :profile_image, styles: {
        large: "600x450#",
        medium: "250x250#",
        small: "100x100#"
    }, :default_url => "/images/:style/filler.png"

    belongs_to :category
    validates :name, :profile_image, presence: true
    extend FriendlyId
    friendly_id :name, use: :slugged

    attr_accessor :slug

end
表格由活动管理员自动为我生成

迁移文件如下所示:

class CreateProfiles < ActiveRecord::Migration
  def change
    create_table :profiles do |t|
      t.string :name
      t.string :slug
      t.string :profile_image
      t.text :content


      t.timestamps
    end
    add_index :profiles, :slug, unique: true
  end
end
有人能提供一些线索来解释为什么会发生这种情况吗


谢谢

您应该在ActiveAdmin文档中查看这篇文章


希望这有帮助

嗯,不,这似乎会引发更多错误,当我这样做时,我的实际资源从active admin的主顶部导航中消失了。你应该尝试更改配置文件的强参数设置。尝试附加params.permit profile:[:name,:profile_image,:content,categories[]@mdunbavanh如何为AA执行此操作?尝试附加params.permit profile:[:name,:profile_image,:content,categories[]]