Friday, 13 September 2013

Polymorphic Association in Active Admin Not Passing All Parameters

Polymorphic Association in Active Admin Not Passing All Parameters

I created a Polymorphic Association in Active Admin for the creation of
Keyword associated with Industry. I can display the association fine in
Active Admin (the association was created in the console) but when I
Update and create New, only the keyword parameters gets passed. If I go
back to the console and update, the updated data is properly displayed in
Active Admin.
I never get an error.
I have:
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"=>"&#10003;",
"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)

No comments:

Post a Comment