我有東西不能像我想在我的控制器中工作。導軌3控制器選擇模型
我控制器
if params[:commit]
@search = Building.select('buildings.id, buildings.slug, floors.id, spaces.id, buildings.name, floors.floor_number, spaces.space_number').joins('INNER JOIN floors ON floors.building_id = buildings.id INNER JOIN spaces ON spaces.floor_id = floors.id')
@search = @search.where("buildings.name like '%#{params[:building_name]}%'") if !params[:building_name].blank?
#@search = @search.where("buildings.name like ?", params[:building_name]) if !params[:building_name].blank?
if params[:space_type].present?
@search = @search.where("spaces.space_type_id = ?", params[:space_type][:space_type_id]) if !params[:space_type][:space_type_id].blank?
end
@search = @search.where("floors.min_net_rent >= #{params[:floor_min_rent]}") if !params[:floor_min_rent].blank?
@search = @search.where("floors.max_net_rent <= #{params[:floor_max_rent]}") if !params[:floor_max_rent].blank?
@building = @search
else
@building = ''
end
我的模型
class Building < ActiveRecord::Base
has_many :floors
end
class Floor < ActiveRecord::Base
belongs_to :building
has_many :space
end
class Space < ActiveRecord::Base
belongs_to :floor
end
調試<%=調試@building%>返回我
[#<Building id: 9, name: "234234", slug: nil>] (as example)
,但我想獲得有關地板的信息和空間。
有人有一個想法如何解決這個問題?
謝謝。
如果您調試/打印'@ building.floors'和'@ building.spaces',會發生什麼?它在'rails console'中工作嗎?也有點困惑爲什麼你繼續分配給@搜索變量;你能一次只搜索一個標準嗎?在客戶端執行? –