Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with ajax in date select
    primarykey
    data
    text
    <p>Excuse me, I am a newbie programmer in Rails. </p> <p>I want use AJAX in a DATE SELECT. when I change the date, change the punitive ammount depends the result of method get_punitive (Model).</p> <p>I use the next code in Controller, Model and View.However the event On change is not recognized. please you could help me.</p> <p>Operations Model (partially)</p> <pre><code>def get_punitive(payment_date, expiration_date) if payment_date &gt; 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 </code></pre> <p>Operations Controller (partially)</p> <pre><code>def cancel @operation = Operation.find(params[:id]) last_pagare = Pagare.find(:first, :conditions =&gt; "operation_id = #{@operation.id} AND state &lt;&gt; '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 =&gt; 'cancel' end </code></pre> <p>View of cancel</p> <h1>Cancelacion de Operaciones</h1> <pre><code>&lt;% form_for(@operation, :url =&gt; submit_cancellation_admin_operation_path) do |f| %&gt; &lt;%= f.error_messages %&gt; &lt;%= text_field_tag :a, :onClick =&gt; "javascript:alert('hola');" %&gt; &lt;p&gt;Fecha de Pago:&lt;br/&gt;&lt;br/&gt; &lt;%= date_select("", :payment_date, {:start_date =&gt; Time.now, :onchange =&gt; remote_function(:url =&gt; {:controller =&gt; 'operations', :action =&gt; "update_payment_date"}, :with =&gt; "'payment_date='+value")}) %&gt; &lt;/p&gt; &lt;p&gt;Prueba &lt;%= collection_select "", :object, Operation.all, :id, :taker_id, { :onChange =&gt; "javascript::alert('hola');", :onClick =&gt; remote_function(:url =&gt; {:controller =&gt; 'operations', :action =&gt; "update_payment_date"}, :with =&gt; "'dgdfg='+value")} %&gt; &lt;/p&gt; &lt;p&gt;Monto a Cancelar (Mayor a cero):&lt;br/&gt;&lt;br/&gt; &lt;%= text_field_tag :ammount , @operation.get_balance(@operation.interest_rate_for_taker) %&gt; &lt;/p&gt; &lt;p&gt;Monto punitorio:&lt;br/&gt;&lt;br/&gt; &lt;%= text_field_tag :punitive_ammount, @punitive_ammount %&gt; &lt;/p&gt; &lt;!--&lt;p&gt;Fecha de Pago:&lt;br/&gt;&lt;br/&gt; &lt;%#= date_select("", :date, :start_year =&gt; Time.now.year-1, :default =&gt; Time.now) %&gt; &lt;/p&gt;--&gt; &lt;% %&gt; &lt;p&gt; &lt;%= f.submit 'Cancelar' %&gt; &lt;/p&gt; &lt;% end %&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload