Rails ActiveAdmin 嵌套表单格式问题
一直试图找出为什么我的表格无法正常工作。 - 这是 我最接近让它工作的时候,它显示了位置字段 当我这样做时,但是当我提交表单时,它显示“未知属性 位置”,我认为这是因为位置实际上应该是 像 f.inputs :name => 一样访问“位置”,:for => :位置做| location_form|,而不是我下面的(对吗?)但是当我这样做时 非复数什么也没有显示出来。如果我用复数形式,则不会 知道如何处理位置属性。谁能告诉我如果我 我做错了什么,或者这是一个错误?非常感谢 进步。
class Store < ActiveRecord::Base
has_one :location
belongs_to :admin_user
accepts_nested_attributes_for :location
end
class Location < ActiveRecord::Base
belongs_to :store
end
ActiveAdmin.register Store do
form do |f|
f.inputs "Details" do
f.input :name
f.input :description
f.input :admin_user
end
f.inputs :name => "Location", :for => :locations do |location_form|
location_form.input :address
end
f.buttons
end
end
Been trying to figure out why my form won't work properly. -- this is
the closest I get to getting it working, it shows the location field
when I do this however when I submit form it says "Unknown attribute
locations", which I believe is because locations should actually be
accessed like f.inputs :name => "Location", :for => :location do |
location_form|, instead of what I have below (right?) but when I do it
non plural nothing shows up at all. If i do it plural, it doesen't
know what to do with the location attributes. Can anyone tell me if I
am doing something wrong, or if this is a bug? Thanks a ton in
advance.
class Store < ActiveRecord::Base
has_one :location
belongs_to :admin_user
accepts_nested_attributes_for :location
end
class Location < ActiveRecord::Base
belongs_to :store
end
ActiveAdmin.register Store do
form do |f|
f.inputs "Details" do
f.input :name
f.input :description
f.input :admin_user
end
f.inputs :name => "Location", :for => :locations do |location_form|
location_form.input :address
end
f.buttons
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许尝试代替
这个
Perhaps try instead of
this
您应该尝试活动管理为您提供的表单构建器对象的
has_many
方法。You should try the
has_many
method of the form builder object active admin gives you.您可以尝试创建位置对象,
You can try by creating location object,