我試圖從tints
實體獲取front, rear, side
屬性的值。無法訪問表屬性的值
廠家{id, name}
模式{id, manufacturer_id, name}
色調{id, manufacturer_id, model_id, front, side, rear}
這是我tints_controller.rb
def generate
@manufacturers = Manufacturer.find(params[:tint][:manufacturer_id])
@models = Model.find(params[:tint][:model_id])
@price_front = Price.find(params[:price][:price_front])
@price_rear = Price.find(params[:price][:price_rear])
@measurements = Tint.where('manufacturer_id' => @manufacturers).where('model_id' => @models)
end
我收到的時候我試圖做<%= @measurements.rear %>
我generate.html.erb
undefined method `rear' for #<Tint::ActiveRecord_Relation:0x0000000c628610>
錯誤
下面是調試屏幕
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"jfV6SUkNdKWO1f1fyzqS4eLbvszjDPNm2E81M90lnvPArYScSjcjQlxsJdcuqQMJ+mSecCsyVQlhz2cpAH1DUw==",
"tint"=>{"manufacturer_id"=>"6", "model_id"=>"3"},
"price"=>{"price_front"=>"1", "price_rear"=>"2"},
"commit"=>"Submit"}
然而,當我做<%= @measurements.inspect %>
,它顯示出低於行,指示在tints_controller
的@measurements
正確定義。它顯示它可以通過搜索正確的model_id
和manufacturer_id
從表中獲得整行。不過,我不能直接做<%= @measurements.front =>
#<ActiveRecord::Relation [#<Tint id: 1, manufacturer_id: 6, model_id: 3, front: 40, side: 50, rear: 60, created_at: "2016-07-22 04:14:49", updated_at: "2016-07-22 04:14:49">]>
我做了什麼,以獲得front, side, rear
值作爲int
: 我試圖做<%= @measurements[:front] =>
和<%= @measurements[:id][:front] =>
,我仍然得到錯誤。