2016-05-06 10 views
0

ich einen BereichWie jeder auf Spielraum für keinen Hash zurückgeben

class HistoricRefinancing < ActiveRecord::Base 
    scope :consult_historic_refin, -> (refinancing_id) { 
    HistoricRefinancing.where("refinancing_id = ? ", "#{refinancing_id}") } 
end 

haben und ich es hier genannt (refinancings_controller.rb):

def cancel_refinancing 

    @hist_refin = HistoricRefinancing.consult_historic_refin(params[:refinancing_id]) 
    @hist_refin.authorization.update_columns(situation: 1) 
    end 

Aber haben zwei Probleme, erste wenn ich Puts auf @hist_refin tun, kehren diese:

------- 
    HistoricRefinancing Load (3.1ms) SELECT "HISTORIC==_REFINANCINGS".* FROM "HISTORIC_REFINANCINGS" WHERE (refinancing_id = '17') 
#<HistoricRefinancing:0x007f616c515cc8> 

Und dieser Fehler:

NoMethodError - undefined method `authorization' for #<HistoricRefinancing::ActiveRecord_Relation:0x007f617b1d35d8>: 

Meine Beziehungen ist richtig, Autorisierung viele Refinanzierungen hat, refinancig zulassungs gehört, hat historische Refinanzierung (entspricht authorization_id, aber ich brauchte Änderung der Name) authorization_origin_id, refinancing_id und authorization_new_id

Alles, was ich will, ist Spalte Wechselsituation für 1, sondern nur für die Refinanzierungen. Wie geht es, bitte?


Als Hilfe Sie:

def cancel_refinancing 

     @hist_refin = HistoricRefinancing.consult_historic_refin(params[:refinancing_id]) 
     @hist_refin.map{|hr| hr.authorization.update_attributes(situation: 1) } 

     end 

Und dieser Fehler, den ich erhalten:

NoMethodError - undefined method `update_attributes' for nil:NilClass: 

= (

+2

nennen FYI sollten Sie 'HistoricRefinancing.where werden (refinancing_id: refinancing_id)' – meagar

Antwort

2

@hist_refin eine Sammlung Sie nicht aufrufen können. Berechtigung für eine Sammlung, Sie können sie nur für eine Instanz von HistoricRefinancing aufrufen. Wenn Sie jede einzelne aktualisieren möchten, können Sie thr zuordnen wegen ihnen.

@hist_refin.map{|hr| hr.update_attributes(situation: 1) } 

Wenn Sie nur die erste Sie @hist_refin.first.authorization.updata_attributes(situation: 1)

+0

Fehler: UnknownAttributeError - unbekanntes Attribut 'Situation' für HistoricRefinancing. : Ich muss mich meinem Umfang anschließen? An der Tabelle Autorisierung teilnehmen? –

+0

NoMethodError - undefinierte Methode 'update_all 'für 20: Fixnum: gib diesen Fehler für mich zurück =/ –

+1

Klasse HistoricRefinancing (refinanzierung_id) { HistoricRefinancing.where (" refinancing_id =? ", "# {refinancing_id}". includes (: authorization)} end –