Ruby on rails 活动管理中的多态关联未传递所有参数
我在Active Admin中创建了一个多态关联,用于创建与行业关联的关键字。我可以在Active Admin中显示关联。关联是在控制台中创建的,但当我更新并创建新关联时,只传递关键字参数。如果我返回控制台进行更新,更新后的数据将正确显示在Active Admin中 我从不出错 我有:Ruby on rails 活动管理中的多态关联未传递所有参数,ruby-on-rails,ruby-on-rails-3,activeadmin,polymorphic-associations,formtastic,Ruby On Rails,Ruby On Rails 3,Activeadmin,Polymorphic Associations,Formtastic,我在Active Admin中创建了一个多态关联,用于创建与行业关联的关键字。我可以在Active Admin中显示关联。关联是在控制台中创建的,但当我更新并创建新关联时,只传递关键字参数。如果我返回控制台进行更新,更新后的数据将正确显示在Active Admin中 我从不出错 我有: class Industry < ActiveRecord::Base attr_accessible :name, :keywords, :keywords_attributes # Ass
class Industry < ActiveRecord::Base
attr_accessible :name, :keywords, :keywords_attributes
# Associations
has_many :profiles
has_many :companies
has_many :users
has_many :keywords, as: :keyable
accepts_nested_attributes_for :keywords
end
class Keyword < ActiveRecord::Base
attr_accessible :name, :profile_id, :active,
:keyable_attributes, :rating,
:keyable_id, :keyable_industry
# Associations
belongs_to :profile # FK
belongs_to :keyable, polymorphic: true
accepts_nested_attributes_for :keyable
attr_accessor :keyable_industry
def keyable_industry
self.keyable.id if self.keyable.is_a? Industry
end
end
ActiveAdmin.register Keyword do
index do
column :name
column :active
column :rating
column "Keyword Group", :keyable
column :keyable_type
default_actions
end
form do |f|
f.inputs "Conference Detail" do
f.input :name
f.input :active
f.input :rating
f.input :keyable_industry
end
f.inputs "Industry" do
f.input :keyable_industry, label: "Industry",
:as => :select,
:collection => Industry.all.map {|i| [i.name]},
:include_blank => false
end
f.actions
end
end
Development Log Output
Started PUT "/admin/keywords/2" for 127.0.0.1 at 2013-09-13 11:41:32 -0400
Processing by Admin::KeywordsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"nnbMIHy1YndWNOKyF+LSABYyeQMpKQAiTyqGbL2sq3g=", "keyword"=> {"name"=>"test", "active"=>"1", "rating"=>"1", "keyable_industry"=>"Agriculture & Forestry"}, "commit"=>"Update Keyword", "id"=>"2"}
User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Keyword Load (0.7ms) SELECT "keywords".* FROM "keywords" WHERE "keywords"."id" = $1 LIMIT 1 [["id", "2"]]
(0.7ms) BEGIN
(1.1ms) UPDATE "keywords" SET "name" = 'test', "updated_at" = '2013-09-13 15:41:32.287147' WHERE "keywords"."id" = 2
(2.9ms) COMMIT
Redirected to http://blog.dev/admin/keywords/2
Completed 302 Found in 14ms (ActiveRecord: 0.0ms)
好的,我让它工作不确定它是否是最好的解决方案。欢迎发表意见 要查看,我的模型有以下内容:
class Industry < ActiveRecord::Base
attr_accessible :name, :keywords, :keywords_attributes
# Associations
has_many :profiles
has_many :companies
has_many :users
has_many :keywords, as: :keyable
accepts_nested_attributes_for :keywords
end
class Keyword < ActiveRecord::Base
attr_accessible :name, :profile_id, :active,
:keyable_attributes, :rating,
:keyable_id, :keyable_industry, :keyable_type
# Associations
belongs_to :profile # FK
belongs_to :keyable, polymorphic: true
accepts_nested_attributes_for :keyable
has_many :conference_keywordeds
has_many :conferences, through: :conference_keywordeds
end
好的,我让它工作不确定它是否是最好的解决方案。欢迎发表意见 要查看,我的模型有以下内容:
class Industry < ActiveRecord::Base
attr_accessible :name, :keywords, :keywords_attributes
# Associations
has_many :profiles
has_many :companies
has_many :users
has_many :keywords, as: :keyable
accepts_nested_attributes_for :keywords
end
class Keyword < ActiveRecord::Base
attr_accessible :name, :profile_id, :active,
:keyable_attributes, :rating,
:keyable_id, :keyable_industry, :keyable_type
# Associations
belongs_to :profile # FK
belongs_to :keyable, polymorphic: true
accepts_nested_attributes_for :keyable
has_many :conference_keywordeds
has_many :conferences, through: :conference_keywordeds
end
protip:当您提供:集合选项时,:select是默认输入类型,因此您不需要as::selectprotip:当您提供:集合选项时,:select是默认输入类型,因此您不需要as::select