Ruby on rails 嵌套模型的Activeadmin
您好,我正在尝试构建一个应用程序,其中我正在使用Activeadmin搜索结果模型。搜索结果模型用于保存付费客人信息。每个PG都有共享类型(如个人、单人、双人)和每个共享类型的价格。我总共创建了三个模型,分别名为搜索结果、共享类型和价格表。 我想创建一个activeadmin表单来保存PG信息以及共享类型和价格表。 在seach_result.rb中Ruby on rails 嵌套模型的Activeadmin,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,您好,我正在尝试构建一个应用程序,其中我正在使用Activeadmin搜索结果模型。搜索结果模型用于保存付费客人信息。每个PG都有共享类型(如个人、单人、双人)和每个共享类型的价格。我总共创建了三个模型,分别名为搜索结果、共享类型和价格表。 我想创建一个activeadmin表单来保存PG信息以及共享类型和价格表。 在seach_result.rb中 class SearchResult < ActiveRecord::Base has_attached_file :pg_imag
class SearchResult < ActiveRecord::Base
has_attached_file :pg_images,:styles => {
:thumb => "100x100#",
:small => "150x150>",
:medium => "400x200" }, default_url: "/images/missing.png"
validates_attachment :pg_images,
content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
has_many :sharing_types ,dependent: :destroy
accepts_nested_attributes_for :sharing_types, allow_destroy: true
end
我在这一点上被绊倒了。有人能帮我完成这项任务吗。有人能帮我。。
class SharingType < ActiveRecord::Base
belongs_to :search_result
has_many :pricelists ,dependent: :destroy
accepts_nested_attributes_for :pricelists, allow_destroy: true
end
class Pricelist < ActiveRecord::Base
belongs_to :sharing_type
end
ActiveAdmin.register SearchResult do
permit_params :gender,:pgname,:pgadress,:pgrent,:secdeposit,:postdate,:image,:pg_images ,:sharing_type,:food_type,:meals_type,:location_cd ,:location_name
form multipart: true do |f|
f.inputs 'PG Details ' do
f.input :gender, :required => false , :label => "Gender"
f.input :pgname, :required => false, :label => "PG Name"
f.input :pgadress, :required => false, :label => "PG Address"
f.input :pgrent, :required => false, :label => "PG Rent"
f.input :secdeposit, :required => false, :label => "PG Deposit"
f.input :postdate, :required => false, :label => "PG Post Date"
f.input :location_cd, :required => false, :label => "Location Code"
f.input :location_name, :required => false, :label => "Location Name"
f.input :food_type, :required => false, :label => "Food Type"
f.input :meals_type, :required => false, :label => "Meals Type"
f.input :pg_images, :required => false, :as => :file
end
f.inputs 'Sharing_types' do |d|
d.input :typename,:as => :select , :collection => SharingType.all
end
f.actions
end
end