2009-06-13 13 views
0

Im Zuge der Erstellung einer Rails-Anwendung, um kleine Hotels verwalten Buchungen zu helfen, stoße ich auf eine seltsame Anwendung hängen. Der Aufbau der Reservierung funktioniert gut; Hinzufügen von Gästen, Zuweisen von Räumen usw. ohne Problem. Wenn der Händler jedoch eine Anfrage "bestätigt", hängt Mongrel mich zum Trocknen aus.Diagnose von Rails-Anwendung Hang on Element Update

Die Indexseite reservieren listet die aktuellen Anfragen und bestätigten Buchungen:

# reservations/index.html.erb 

<% unless @reservations.empty? %> 
<h2>Inquiries</h2><hr/><br/> 
<%= render :partial => 'reservation', :collection => @reservations.reject { |r| r.confirmed } %> 
<h2>Confirmed Reservations</h2><hr/><br/> 
<%= render :partial => 'reservation', :collection => @reservations.reject { |r| not r.confirmed } %> 
<% else %> 
<%= link_to 'Search for rooms', :action => 'index', :controller => 'search' %> 
<% end %> 

In der Reservierung teilweise selbst, die Bits, die die Bestätigungs/unconfirm Logik aufrufen einfach direkte Links Aktionen zum Controller:

# _reservation.html.erb 

(<% unless reservation.confirmed? %> 
    <%= link_to 'Confirm Reservation', :action => 'confirm', :id => reservation.id %> 
<% else %> 
    <%= link_to 'Unconfirm Reservation', :action => 'unconfirm', :id => reservation.id %> 
<% end %>) 

Der Regler eine Reservierung zu bestätigen, die zu einem PUT in meine Routen zugeordnet ist, sieht wie folgt aus:

def confirm 
    puts "\n\n\nConfirming reservation #{params[:id]}..." 
    @reservation = Reservation.find(params[:id]) 
    puts "Found reservation! Confirming..." 
    @reservation[:confirmed] = true 
    puts "Confirmed, saving..." 
    respond_to do |wants|    
    if @reservation.save 
     flash[:notice] = 'Reservation has been confirmed.' 
     wants.html { redirect_to :action => 'index' } 
    else 
     wants.html { render :action => 'index' } 
    end 
    end  
end 

'@ reservation.save' ist, was den Trick macht. Bestimmte App hängt jedes Mal.

Kann mir jemand helfen zu verstehen, was hier vor sich geht?

/UPDATE:

Von Herumspielen mit der Konsole ich in der Lage war, das Problem auf eine andere Weise zu demonstrieren:

?> r = Reservation.find(36) 
=> #<Reservation id: 36, customer_name: "buyer", customer_email: "[email protected]", begin: "2009-06-22 00:00:00", end: "2009-06-26 00:00:00", request_timestamp: nil, notes: "Thanks!", created_at: "2009-06-13 20:36:50", updated_at: "2009-06-13 20:36:50", yacht_id: 7, adults: 1, children: 0, buyer_id: 3, confirmed: nil> 
>> r.confirmed = true 
=> true 
>> r 
=> #<Reservation id: 36, customer_name: "buyer", customer_email: "[email protected]", begin: "2009-06-22 00:00:00", end: "2009-06-26 00:00:00", request_timestamp: nil, notes: "Thanks!", created_at: "2009-06-13 20:36:50", updated_at: "2009-06-13 20:36:50", yacht_id: 7, adults: 1, children: 0, buyer_id: 3, confirmed: true> 
>> r.save! 
IRB::Abort: abort then interrupt!! 
    from C:/Ruby/lib/ruby/1.8/irb.rb:81:in `irb_abort' 
    from C:/Ruby/lib/ruby/1.8/irb.rb:247:in `signal_handle' 
    from C:/Ruby/lib/ruby/1.8/irb.rb:66:in `start' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:275:in `call' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:275:in `run_callbacks' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/callbacks.rb:344:in `callback' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/callbacks.rb:318:in `valid?' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_proxy.rb:221:in `send' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/associations/association_proxy.rb:221:in `method_missing' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:906:in `validates_associated' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:906:in `collect' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:906:in `validates_associated' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:399:in `validates_each' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:396:in `each' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:396:in `validates_each' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:182:in `call' 
... 2204 levels... 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:90:in `run' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:90:in `each' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:90:in `send' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:90:in `run' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/callbacks.rb:276:in `run_callbacks' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:1029:in `valid_without_callbacks?' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/callbacks.rb:315:in `valid?' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:1018:in `save_without_dirty!' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/dirty.rb:87:in `save_without_transactions!' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:200:in `save!' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:182:in `transaction' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:200:in `save!' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:208:in `rollback_active_record_state!' 
    from C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/transactions.rb:200:in `save!' 
    from (irb):5>> 

Beachten Sie, dass die Konsole als auch eingesperrt, und ich hatte die zum Abbruch sparen! Befehl mit Strg-C.

Warum in der Welt würde sparen! tust du das?

/UPDATE:

Verstanden !!! Es war in meinem Modell. Ich habe versucht, einen Verband zu validieren, und ich hatte die has_many/gehört_to Sachen rückwärts.

Danke, alle!

+1

Problem scheint gelöst zu sein (und Antwort ist inline in der Frage) ... Es sieht nicht so aus, als ob Post tatsächlich genug Informationen enthält, um Probleme zu demonstrieren - so unwahrscheinlich, dass sie für andere Leser nützlich sind. –

Antwort

0

Verwenden Sie thin statt Mongrel. Veröffentlichen Sie weitere Details aus Ihrem Protokoll. Es hängt normalerweise nicht so.

+0

Ich habe noch nicht dünn versucht, aber in den Protokollen heißt es: Bestätigung Reservierung 36 ... Gefunden Reservierung! Bestätigen ... Bestätigt, Speichern ... Und dann nichts - die Statusleiste des Browsers hängt auch bei 0% geladen.Und ohne die puts-Anweisungen stoppt das Protokoll einfach nach der Anzeige von Informationen zum Rendering/Index. –

1

Ihr Problem kann sein:

@reservation[:confirmed] = true 

Sie direkt auf die Attribute Hash-Aktualisierung, die ein wenig seltsam ist. Normalerweise würden Sie nur das Attribut aktualisieren.

Ich hatte schon vorher Probleme, wenn ich mit dem Attribut Hash versaute. Vor allem Booleans - vielleicht, weil es eine Art Zwang gibt.

+0

Danke, aber das war es leider nicht ... –