2010-12-27 8 views
0

Entschuldigen Sie, ich bin ein Anfänger Programmierer in Rails.Problem mit AJAX in Datum wählen

Ich möchte AJAX in einem DATUM SELECT verwenden. Wenn ich das Datum ändere, ändern Sie den Strafbetrag, der vom Ergebnis der Methode get_punitive (Model) abhängt.

Ich verwende den nächsten Code in Controller, Model und View. Das Ereignis On change wird jedoch nicht erkannt. bitte könntest du mir helfen.

Betriebsmodell (teilweise)

def get_punitive(payment_date, expiration_date) 
    if payment_date > expiration_date 
    expiration_days= (payment_date - expiration_date).to_i 
    else 
    expiration_days = 0 
    end 
    punitive_ammount = (self.capital * (self.interest_rate_for_taker/100.0) * expiration_days)/30 
    # raise punitive_ammount.inspect 
    end 

Operationen Controller (teilweise)

def cancel 
    @operation  = Operation.find(params[:id]) 
    last_pagare  = Pagare.find(:first, :conditions => "operation_id = #{@operation.id} AND state <> 'cancelled'") 
    @punitive_ammount = @operation.get_punitive(DateTime.now.to_date, last_pagare.expiration_date.to_date) 
    end 

    def update_payment_date 
    raise params.inspect 
    end 

    def submit_cancellation 
    @operation  = Operation.find(params[:id]) 
    ammount   = params[:ammount] 
    punitive_ammount = (params[:punitive_ammount].blank?) ? 0 : params[:punitive_ammount] 
    payment_date  = Date.new(params[:"payment_date(1i)"], params(:"payment_date(2i)"), params(:"payment_date(3i)")) 
    admin   = User.find_by_login('admin') 
    if @operation.cancel(ammount, punitive_ammount, admin, payment_date) 
     respond_to do |format| 
     format.html { redirect_to(admin_operations_url) } 
     format.xml { head :ok } 
     end 
    else 
     @operation.errors.add_to_base("Los montos ingresados son invalidos") 
     render :action => 'cancel' 
    end 

Ansicht des Löschens

Cancelación de Operaciones

<% form_for(@operation, :url => submit_cancellation_admin_operation_path) do |f| %> 
    <%= f.error_messages %> 

    <%= text_field_tag :a, :onClick => "javascript:alert('hola');" %> 

    <p>Fecha de Pago:<br/><br/> 
    <%= date_select("", :payment_date, {:start_date => Time.now, :onchange => remote_function(:url => {:controller => 'operations', :action => "update_payment_date"}, :with => "'payment_date='+value")}) %> 
    </p> 

    <p>Prueba 
     <%= collection_select "", :object, Operation.all, :id, :taker_id, { :onChange => "javascript::alert('hola');", :onClick => remote_function(:url => {:controller => 'operations', :action => "update_payment_date"}, :with => "'dgdfg='+value")} %> 
    </p> 
    <p>Monto a Cancelar (Mayor a cero):<br/><br/> 
    <%= text_field_tag :ammount , @operation.get_balance(@operation.interest_rate_for_taker) %> 
    </p> 

    <p>Monto punitorio:<br/><br/> 
    <%= text_field_tag :punitive_ammount, @punitive_ammount %> 
    </p> 

    <!--<p>Fecha de Pago:<br/><br/> 
    <%#= date_select("", :date, :start_year => Time.now.year-1, :default => Time.now) %> 
    </p>--> 
    <% %> 
    <p> 
    <%= f.submit 'Cancelar' %> 
    </p> 

<% end %> 

Antwort

1

Hallo Format o f date_select Helfer ist

date_select(object_name, method, options = {}, html_options = {}) 

Sie haben

<%= date_select("", :payment_date, {:start_date => Time.now, :onchange => remote_function(:url => {:controller => 'operations', :action => "update_payment_date"}, :with => "'payment_date='+value")}) %> 

versuchen

<%= date_select("", :payment_date, {:start_date => Time.now}, {:onchange =>"javascript::alert('hola');"}) %> 

das gleiche über collection_select

collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {}) 

Sie haben

<%= collection_select "", :object, Operation.all, :id, :taker_id, { :onChange => "javascript::alert('hola');", :onClick => remote_function(:url => {:controller => 'operations', :action => "update_payment_date"}, :with => "'dgdfg='+value")} %> 

versuchen

<%= collection_select "", :object, Operation.all, :id, :taker_id, {}, { :onChange => "javascript::alert('hola');"}%> 
+0

Thank you.Now die date_select und collection_select das Ereignis erkannt. – maxiperez