Rails ActiveAdmin 嵌套表单格式问题

发布于 2024-12-14 02:01:35 字数 778 浏览 1 评论 0原文

一直试图找出为什么我的表格无法正常工作。 - 这是 我最接近让它工作的时候,它显示了位置字段 当我这样做时,但是当我提交表单时,它显示“未知属性 位置”,我认为这是因为位置实际上应该是 像 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑叹一世浮沉 2024-12-21 02:01:35

也许尝试代替

f.inputs :name => "Location", :for => :locations do |location_form|
  location_form.input :address
end

这个

f.inputs :name => "Location", :for => [f.object.location || Location.new] do |location_form|
  location_form.input :address
end

Perhaps try instead of

f.inputs :name => "Location", :for => :locations do |location_form|
  location_form.input :address
end

this

f.inputs :name => "Location", :for => [f.object.location || Location.new] do |location_form|
  location_form.input :address
end
辞取 2024-12-21 02:01:35

您应该尝试活动管理为您提供的表单构建器对象的 has_many 方法。

f.has_many :locations do |location_form|
  location_form.input :name
end

You should try the has_many method of the form builder object active admin gives you.

f.has_many :locations do |location_form|
  location_form.input :name
end
∞琼窗梦回ˉ 2024-12-21 02:01:35

您可以尝试创建位置对象,

f.semantic_fields_for :locations, Location.new do |ff|
  ff.input :name
end

You can try by creating location object,

f.semantic_fields_for :locations, Location.new do |ff|
  ff.input :name
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文