Jeh*_*adK 4 ruby ruby-on-rails has-many-through activeadmin ruby-on-rails-4
我已经尝试了好几天了,我是ROR和活跃管理员的新手.到目前为止,我已经能够为新记录添加和删除has_many关系.我使用的是strong_parameters以及accept_nested_attributes.我想要
理想情况下,应该有一个自动完成框,允许搜索和选择此特定模型的现有含义.
我的模特是
我只想要附加已经可用于单词的含义的功能吗?
class Word < ActiveRecord::Base
belongs_to :language
has_many :word_meanings
has_many :meanings ,through: :word_meanings
Run Code Online (Sandbox Code Playgroud)
form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs do
f.input :language
f.input :word
f.input :wordInScript
f.input :pronunciation, :required => false, :as => :file
end
f.inputs do
f.has_many :meanings, heading: 'Meanings', allow_destroy: true, new_record: true do |a|
a.input :meaning
a.input :language
end
end
f.actions
end
Run Code Online (Sandbox Code Playgroud)
您可以确定选择的集合:
a.input :meaning, :as => :select, :collection => {#your collection in Hash, Array or ActiveRecord relation}.map{|key, value| [value, key] }
Run Code Online (Sandbox Code Playgroud)
ActiveAdmin使用Formtastic:https: //github.com/justinfrench/formtastic#usage