我知道,我應該知道這一點的關聯列表,但我似乎無法弄清楚在所有和我還是新發展......如何限制基於相關模型
所以我有四款機型...
約會
class Appointment < ActiveRecord::Base
belongs_to :user
belongs_to :profile
belongs_to :location
end
型材
class Profile < ActiveRecord::Base
belongs_to :user
has_many :appointments
has_many :profile_locations
has_many :locations, through: :profile_locations
accepts_nested_attributes_for :profile_locations, reject_if: :all_blank, allow_destroy: true
accepts_nested_attributes_for :locations, reject_if: :all_blank, allow_destroy: true
end
profile_locations
class ProfileLocation < ActiveRecord::Base
belongs_to :profile
belongs_to :location
belongs_to :location_type
accepts_nested_attributes_for :location
end
和地點
class Location < ActiveRecord::Base
has_many :profile_locations
has_many :profiles, through: :profile_locations
has_many :appointments
end
在創建約會頁,我已經在記錄相關的配置文件。我也有一個關於我的simple_form的關聯字段,我希望能夠根據與個人資料綁定的約會分配位置。
我正在嘗試這樣的事情,但似乎無法工作。
%td= f.association :location, :as => :collection_select, collection: Location.where(location.profile_location.profile_id: @profile.id), label_method: :address_1, value_method: :id, include_blank: false, :input_html => {:class => "input-small"}, :label => "Select The Location"
我在這裏丟失了什麼,或者有沒有更簡單的方法來查詢?任何這方面的指導都會有所幫助。
你能否詳細解釋一下。 –