Проблема с ajax в выборе даты - PullRequest
0 голосов
/ 27 декабря 2010

Извините, я новичок в Rails.

Я хочу использовать AJAX для выбора даты. когда я изменяю дату, изменение штрафной суммы зависит от результата метода get_punitive (Model).

Я использую следующий код в Controller, Model и View. Однако событие On change не распознается. пожалуйста, вы могли бы помочь мне.

Операционная модель (частично)

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

Операционный контроллер (частично)

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

Просмотр отмены

Cancelacion 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  %>

1 Ответ

1 голос
/ 28 декабря 2010

Привет формат date_select Помощник

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

у вас есть

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

1008 * попробовать *

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

то же самое о collection_select

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

у вас есть

<%= 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")} %>

попробуйте

<%= collection_select "", :object, Operation.all, :id, :taker_id, {}, { :onChange => "javascript::alert('hola');"}%>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...