我认为这是一个相对容易的问题,我在抓住Rails时遇到了困难。
如何让Rails接受对象属性的多个值?我如何显示这些项目。目前,当我尝试显示时,在创建项目后它有空白字段。
我正在使用Active Admin,因此下面的许可证看起来有点不同,但与控制器中的概念相同。
这是代码(输入表格和参数在下面):
ActiveAdmin.register Object do
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
permit_params :name, :description, :price, :style_number, :design, :picture, :materials, :country_made_in, collection_colour_id: []
#
# or
#
# permit_params do
# permitted = [:permitted, :attributes]
# permitted << :other if params[:action] == 'create' && current_user.admin?
# permitted
# end
form do |f|
f.semantic_errors *f.object.errors.keys
f.input :name
f.input :style_number, required: true
f.input :design, required: true
f.input :materials, required: true
f.input :country_made_in, required: true
f.input :description
f.input :collection_colour_id, multiple: true, required: true, :label => 'Colours', :as => :check_boxes, :collection => CollectionColour.all.collect {|u| [u.colour_name, u.id]}
f.input :collection_colour_id, multiple: true, required: true, :label => 'Colours', :as => :check_boxes, :collection => CollectionColour.all.collect {|u| [u.colour_name, u.id]}
f.inputs "Upload" do
f.input :picture, required: true, as: :file
end
f.input :price
f.actions
end
end
collection_colour_id
从collection_colour
模型中收集。目前,当我创建新对象时,不接受collection_colour
的任何值。感谢任何帮助!