每个在范围内如何不 return 散列
How do each on scope for don't return a hash
我有一个范围
class HistoricRefinancing < ActiveRecord::Base
scope :consult_historic_refin, -> (refinancing_id) {
HistoricRefinancing.where("refinancing_id = ? ", "#{refinancing_id}") }
end
我在这里调用它 (refinancings_controller.rb):
def cancel_refinancing
@hist_refin = HistoricRefinancing.consult_historic_refin(params[:refinancing_id])
@hist_refin.authorization.update_columns(situation: 1)
end
但是有两个问题,首先当我穿上@hist_refin,return 这个:
-------
HistoricRefinancing Load (3.1ms) SELECT "HISTORIC==_REFINANCINGS".* FROM "HISTORIC_REFINANCINGS" WHERE (refinancing_id = '17' )
#<HistoricRefinancing:0x007f616c515cc8>
还有这个错误:
NoMethodError - undefined method `authorization' for #<HistoricRefinancing::ActiveRecord_Relation:0x007f617b1d35d8>:
我的关系是正确的,授权有很多再融资,再融资属于授权,历史再融资有authorization_origin_id(相当于authorization_id,但我需要改名),refinancing_id和authorization_new_id
我想要的只是改变1的列情况,但只授权再融资。请问怎么做呢?
有你的帮助:
def cancel_refinancing
@hist_refin = HistoricRefinancing.consult_historic_refin(params[:refinancing_id])
@hist_refin.map{|hr| hr.authorization.update_attributes(situation: 1) }
end
我收到这个错误:
NoMethodError - undefined method `update_attributes' for nil:NilClass:
=(
@hist_refin是一个集合。您不能在集合上调用授权,只能在 HistoricRefinancing 的实例上调用它。如果你想更新每一个,你可以通过它们映射。
@hist_refin.map{|hr| hr.update_attributes(situation: 1) }
如果你只想要第一个,你可以打电话@hist_refin.first.authorization.updata_attributes(situation: 1)
我有一个范围
class HistoricRefinancing < ActiveRecord::Base
scope :consult_historic_refin, -> (refinancing_id) {
HistoricRefinancing.where("refinancing_id = ? ", "#{refinancing_id}") }
end
我在这里调用它 (refinancings_controller.rb):
def cancel_refinancing
@hist_refin = HistoricRefinancing.consult_historic_refin(params[:refinancing_id])
@hist_refin.authorization.update_columns(situation: 1)
end
但是有两个问题,首先当我穿上@hist_refin,return 这个:
-------
HistoricRefinancing Load (3.1ms) SELECT "HISTORIC==_REFINANCINGS".* FROM "HISTORIC_REFINANCINGS" WHERE (refinancing_id = '17' )
#<HistoricRefinancing:0x007f616c515cc8>
还有这个错误:
NoMethodError - undefined method `authorization' for #<HistoricRefinancing::ActiveRecord_Relation:0x007f617b1d35d8>:
我的关系是正确的,授权有很多再融资,再融资属于授权,历史再融资有authorization_origin_id(相当于authorization_id,但我需要改名),refinancing_id和authorization_new_id
我想要的只是改变1的列情况,但只授权再融资。请问怎么做呢?
有你的帮助:
def cancel_refinancing
@hist_refin = HistoricRefinancing.consult_historic_refin(params[:refinancing_id])
@hist_refin.map{|hr| hr.authorization.update_attributes(situation: 1) }
end
我收到这个错误:
NoMethodError - undefined method `update_attributes' for nil:NilClass:
=(
@hist_refin是一个集合。您不能在集合上调用授权,只能在 HistoricRefinancing 的实例上调用它。如果你想更新每一个,你可以通过它们映射。
@hist_refin.map{|hr| hr.update_attributes(situation: 1) }
如果你只想要第一个,你可以打电话@hist_refin.first.authorization.updata_attributes(situation: 1)