通过简单的形式选择

时间:2013-08-08 10:16:00

标签: ruby-on-rails ruby-on-rails-3

有一个问题,我无法选择地区。 我有三个型号,spot => city,city =>区域。在模型现场没有场区域。

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 ??

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

1 个答案:

答案 0 :(得分:0)

尝试使用simple_form中的rails wrapper:

= 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"  

由于