0

有问题,我不能选择地区。我有三个模型,spot => city,city => region。在模型现场没有现场区域。

class Spot < ActiveRecord::Base
  belongs_to :city
end

class City < ActiveRecord::Base
  belongs_to :region
end

class Region < ActiveRecord::Base
end

= simple_form_for(@spot, :url => admin_spot_index_path) do |f|
  = f.error_notification
  = f.association :city, :collection => City.all, label: false
  #TODO
  Select region ??

如何以简单的形式表示选择区域?

4

1 回答 1

0

在 simple_form 中尝试 Rails 包装器,如下所示:

= simple_form_for(@spot, :url => admin_spot_index_path) do |f|
  = f.error_notification
  = f.association :city, :collection => City.all, label: false
  = f.input :region do
    = f.select :region, Region.all.map { |r| [r.name, r.id] }, :prompt => "select Region"  

谢谢

于 2013-08-08T10:23:48.237 回答