For my current project I had to add nested form for belongs_to relationship. After lots of searching i found a solution.
12345
class Product<ActiveRecord::Base
belongs_to :cost, :class_name => 'Currency', foreign_key: 'cost_id'
accepts_nested_attributes_for :cost
attr_accessor :cost_id
end
12345
class Currency < ActiveRecord::Base
def self.currency_types
['SAR','AED','USD','EUR','INR']
end
end
123456789101112131415161718192021222324
ActiveAdmin.registerProductdo
form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs "Details" do
f.input :name
f.inputs "cost" do
f.semantic_fields_for :cost_attributes do |j|
j.inputs do
j.input :currency_type, :as => :select, :collection => Currency.currency_types,:label =>'Cost'
j.input :value
end
end
end
end
end
f.actions
end
controller do
def permitted_params
params.permit product: [:name,cost_attributes:[:id,:currency_type,:value]]
end
end
end